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/ */
/**
* 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
}