PHP code example of telkins / laravel-job-funneling-middleware

1. Go to this page and download the library: Download telkins/laravel-job-funneling-middleware 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/ */

    

telkins / laravel-job-funneling-middleware example snippets


namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Telkins\JobFunnelingMiddleware\Funneled;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function handle()
    {
        // your job logic
    }

    public function middleware()
    {
        return [new Funneled()];
    }
}

/*
 * Determine the time at which the job should timeout.
 *
 */
public function retryUntil() :  \DateTime
{
    return now()->addDay();
}

// in your job

public function middleware()
{
    $funneledMiddleware = (new Funneled())
        ->limit(3)
        ->releaseAfterSeconds(90);

    return [$funneledMiddleware];
}

// in your job

public function middleware()
{
    $funneledMiddleware = (new Funneled())
        ->connection('my-custom-connection')
        ->key('my-custom-key');

    return [$funneledMiddleware];
}

// in your job

public function middleware()
{
    $shouldFunnelJobs = Carbon::now()->month === 1;

    $funneledMiddleware = (new Funneled())
        ->enabled($shouldFunnelJobs);

    return [$funneledMiddleware];
}