PHP code example of aaronfrancis / enqueue

1. Go to this page and download the library: Download aaronfrancis/enqueue 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/ */

    

aaronfrancis / enqueue example snippets




namespace App\Jobs;

use AaronFrancis\Enqueue\Contracts\Enqueueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class SyncInventory implements ShouldQueue, Enqueueable
{
    use Queueable;

    public function __construct(public int $warehouseId) {}

    public function handle(): void
    {
        // Sync inventory for this warehouse...
    }

    public static function enqueue(): void
    {
        Warehouse::all()->each(function ($warehouse) {
            dispatch(new static($warehouse->id));
        });
    }
}

// routes/console.php
Schedule::command('jobs:enqueue')->everyMinute();

use Illuminate\Console\Scheduling\CallbackEvent;

public static function shouldEnqueue(CallbackEvent $event): CallbackEvent
{
    return $event->hourly()->weekdays();
}

public static function shouldEnqueue(CallbackEvent $event): bool
{
    return Cache::get('sync_enabled', true);
}
bash
php artisan jobs:enqueue --pretend