PHP code example of pdffiller / laravel-queue-qless

1. Go to this page and download the library: Download pdffiller/laravel-queue-qless 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/ */

    

pdffiller / laravel-queue-qless example snippets


    'connections' => [
        // ...
        'qless' => [
            'driver' => 'qless',
            'redis_connection' => 'qless',
            'queue' => 'default',
        ],
        // ...    
    ],

    'default' => env('QUEUE_DRIVER', 'qless'),

    'redis' => [

        'client' => 'predis',

        // ...
        'qless' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
        // ...
    ],



return [
    //...
    'providers' => [
        //...
        /**
         * Qless
         */
         LaravelQless\LaravelQlessServiceProvider::class,
    ]
];

/**
 * Subscribe
 */

\Queue::subscribe('*.*.test', 'queue1');

\Queue::subscribe('this.*.test', 'queue2');

\Queue::subscribe('this.*.orange', 'queue3');


/**
 * Put job to few queues
 */
\Queue::pushToTopic('this.is.test', TestQless::class, ['test' => 'test']);
// Push job to queue1 and queue2, but not to queue3



    class CustomHandler implements JobHandler
    {
        public function perform(BaseJob $job): void
        {
            if ($job->getQueue() === 'queue_name') { // by queue
                (new QueueNameJob)->perform($job);
                return;
            }
            
            if ($job->getData()['option_name'] === 'value') { // by payload
                (new OptionNameJob)->perform($job);
                return;
            }
            
            if (in_array('tag_name', $job->getTags())) { // by tag
                (new TagNameJob)->perform($job);
                return;
            }
            
            // other
            
            $job->perform(); // Default
        }
    }
    


    public function boot()
    {
        // other code

        $this->app->bind(JobHandler::class, CustomHandler::class);
        
        // other code
    }


/**
 * Recurring Job
 */
 
\Queue::recur($intervalInSeconds, $jobClass, $data, $queueName); 


return [
    'redis' => [
        // ...
        'qless' => [ /* ... */ ],
        'connection2' => [ /* ... */ ],
        'connection3' => [ /* ... */ ],
        // ...
    ],
];

return [
    'connections' => [
        // ...
        'qless' => [
            // ...
            'redis_connection' => [
                'connection2',
                'connection3',
            ],
            // ...
        ],
        // ...
    ],
];