PHP code example of nsumbadze / horizonflow

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

    

nsumbadze / horizonflow example snippets


use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\InteractsWithQueue;
use Laravel\Horizon\Concerns\InteractsWithCancellation;

class SendCampaignMail implements ShouldQueue
{
    use InteractsWithQueue;
    use InteractsWithCancellation;

    public function handle(): void
    {
        foreach ($this->recipients as $recipient) {
            if ($this->cancelIfRequested()) {
                return;
            }

            $this->sendTo($recipient);
        }
    }
}

use Laravel\Horizon\Concerns\InteractsWithCancellation;

final class FetchCitrusPageJob implements ShouldQueue
{
    use InteractsWithCancellation;

    public function __construct(
        public readonly int $companyId,
        public readonly int $page = 1,
    ) {
    }

    public function cancellationGroup(): ?string
    {
        return "citrus-sync:{$this->companyId}";
    }

    public function handle(): void
    {
        foreach ($this->pageOfProducts() as $product) {
            if ($this->cancelIfRequested()) {
                return;
            }

            $this->process($product);
        }

        self::dispatch($this->companyId, $this->page + 1);
    }
}

'dispatch' => [
    'allowed' => [
        'App\Jobs\*',
        'Vendor\Package\Jobs\SyncCatalog',
    ],

    'denied' => [
        'App\Jobs\Billing\*',
    ],
],
bash
php artisan vendor:publish --tag=horizonxflow-config
bash
php artisan horizon
bash
php artisan horizonxflow:demo-jobs
php artisan horizonxflow:demo-jobs --clear