PHP code example of kpconnell / laravel-jobwarden

1. Go to this page and download the library: Download kpconnell/laravel-jobwarden library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kpconnell / laravel-jobwarden example snippets


config('jobwarden.connection')

use JobWarden\Contracts\JobWardenJob;
use JobWarden\Dispatch\Dispatchable;
use JobWarden\Runner\JobContext;

final class ImportCatalog implements JobWardenJob
{
    use Dispatchable;

    public function __construct(
        private readonly string $storeId,
        private readonly bool $fullSync = false,
    ) {
    }

    public function handle(JobContext $context, ?CatalogClient $client = null): void
    {
        // $client is container-injected per run.
        // Constructors are data-only.
        //
        // Do the work here.
        // Returning means success.
        // Throwing means failure.
    }

    public function idempotent(): bool
    {
        return true;
    }
}

ImportCatalog::dispatch('store-42', fullSync: true);

ImportCatalog::inLane('reports')
    ->delay(300)
    ->maxAttempts(3)
    ->dispatch(storeId: 'store-42');

use JobWarden\JobWarden;

app(JobWarden::class)->dispatch(
    ImportCatalog::class,
    ['storeId' => 'store-42'],
    [
        'idempotent' => true,
        'max_attempts' => 3,
        'priority' => 10,
        'available_at' => now()->addMinutes(5),
    ],
);

use JobWarden\JobWarden;

app(JobWarden::class)->batch('nightly-sync', failurePolicy: 'continue')
    ->add('extract', ExtractJob::class, ['store_id' => 42])
    ->add('transform', TransformJob::class, ['store_id' => 42], dependsOn: ['extract'])
    ->add('load', LoadJob::class, ['store_id' => 42], dependsOn: ['transform'])
    ->add('report', ReportJob::class, [], dependsOn: ['load'])
    ->dispatch();

use JobWarden\JobWarden;

$jw = app(JobWarden::class);

$jw->schedule(
    'hourly-metrics',
    '0 * * * *',
    ComputeMetrics::class,
);

$jw->scheduleCommand(
    'nightly-prune',
    '0 3 * * *',
    'cache:prune',
);

$jw->scheduleOnce(
    'one-off-digest',
    now()->addHour(),
    SendDigest::class,
);

config('jobwarden.api.prefix')

config('jobwarden.dashboard.prefix')

use JobWarden\JobWarden;

JobWarden::auth(
    fn ($request) => $request->user()?->can('viewJobWarden') ?? false
);
bash
php artisan jobwarden:work
php artisan jobwarden:reap:global
php artisan jobwarden:schedule
bash
docker compose run --rm migrate

php vendor/bin/testbench package:test