Command bus queue package for Laravel 6. Executes commands using nztim/commandbus.
composer require nztim/queue- Add
NZTim\Queue\QueueServiceProvider::class,toconfig/app.php - Run
php artisan qm:migration && php artisan migrateto add the queue table
$qm->add($command)will add a command to the queue.php artisan qm:processwill process all jobs in the queue.- Job failures will be logged as warnings, and final failures as errors.
- Queue processing is normally triggered via cron.
php artisan qm:daemon 50processes the queue repeatedly for at least as long as the period specified (seconds).- A lockfile is created in the storage folder to allow only only a single process to run.
- It is recommended to not use
withoutOverlapping()because if for any reason it's file mutex is not cleared then execution will halt indefinitely. - A warning will be logged if queue processing is skipped. This may indicate a lot of jobs or slow execution.
- If something goes wrong and the lockfile is not cleared, it will time out after 20 minutes at which time normal processing will resume.
- It is recommended to not use
- Completed jobs are purged after 1 month.
php artisan qm:pause [10]pauses the queue for the specified number of minutes or until manually resumed.php artisan qm:resumeresumes paused queue processing if paused.- Typically surround your deployments with
pauseandresume
- Typically surround your deployments with
php artisan qm:logstatuslogs queue statistics for the last 24 hours
Example Task Scheduler:
$schedule->command('qm:daemon 50')->everyMinute();
$schedule->command('qm:logstatus')->dailyAt('4:00');
Other commands:
php artisan qm:status [24]displays the queue status over the specified period (default 24 hours)php artisan qm:list [7]lists all jobs within the specified number of daysphp artisan qm:failedlists all failed jobsphp artisan qm:dump {id}dumps contents of a particular job idphp artisan qm:retry {id}retry failed job one more timephp artisan qm:clearclears failed jobs from the queue
- 9.0: Update to PHP 7.4 syntax
- 8.0: Move to execution via command bus, remove use of Eloquent, major revision.
- 7.0: Remove facade and .env entries.
- 6.4: Add retry command
- 6: Replace cache lock with lockfile. Add
resume()method.- To upgrade: add
resumeto deployment scripts after deployment is complete.
- To upgrade: add
- 5: Add
daemon()method for faster processing. Addpause()for reliable deployments.- To upgrade: replace use
daemonvia cron instead ofprocess, add dailylogstatuscron, update deployment process to usepause 10followed by cache clear on completion
- To upgrade: replace use
- 4:
QueueMgr::check()removed as is use ofwithoutOverlapping()QUEUEMGR_EMAILandQUEUEMGR_MAX_AGEoptions removed- To upgrade, just remove the unnecessary calls and .env options. Use your error handler (e.g. Logger) for email notifications of failures.