smitmartijn / laravel-pausable-jobs
Pause and resume Laravel jobs individually, instead of having to pause the entire queue.
Package info
github.com/smitmartijn/laravel-pausable-jobs
pkg:composer/smitmartijn/laravel-pausable-jobs
Requires
- php: ^8.2
- laravel/framework: ^10.0 || ^11.0 || ^12.0 || ^13.0
README
Pause and resume individual Laravel job classes without stopping your entire queue. Imagine you have a ton of queue jobs running, and you need to do maintenance on a part of the application, and only a select few jobs touch that part of the application.
Being able to pause specific job classes will let you run your maintenance without slowing down the rest of the application jobs.
Features
- Pause/resume individual job classes
- Works with multiple queue workers
- Redis or Cache driver support to store pause states
- Optional logging of pause/resume actions
- Compatible with Laravel Horizon
- No impact on other running jobs
- Gradual backoff for paused job retries (configurable delays)
- Configurable max retry time before a paused job is marked as failed
Installation
composer require smitmartijn/laravel-pausable-jobs php artisan vendor:publish --tag=pausable-jobs-config
Usage
- Add the trait to your job:
use Smitmartijn\PausableJobs\Concerns\PausableJob; class ProcessVideoJob implements ShouldQueue { use PausableJob; public function handle() { // Your job logic } }
- Control job execution:
use App\Jobs\ProcessVideoJob; use Smitmartijn\PausableJobs\Facades\JobPause; // Pause ProcessVideoJob JobPause::pauseJobClass(ProcessVideoJob::class); // Resume ProcessVideoJob JobPause::resumeJobClass(ProcessVideoJob::class); // Check status if (JobPause::isPaused(ProcessVideoJob::class)) { // Job is paused }
Configuration
config/pausable-jobs.php:
return [ // Use the 'redis' or 'cache' driver - this is where the job pause state is stored 'driver' => env('PAUSABLE_JOBS_DRIVER', 'redis'), // Backoff delays (in seconds) between retries while a job is paused. // Works like Laravel's $backoff property: each entry is used in order, // and the last value repeats for all subsequent retries. 'backoff' => [30, 60, 90, 120, 300], // The maximum number of seconds a job can be retried before it is marked as failed 'max_retry_time' => env('PAUSABLE_JOBS_MAX_RETRY_TIME', 3600), // Logging configuration, which will log when a job is retried because its paused 'logging' => [ 'enabled' => env('PAUSABLE_JOBS_LOGGING', true), 'channel' => env('PAUSABLE_JOBS_LOG_CHANNEL', 'stack'), ], ];
Pause State Manager with Filament v3
I've included an example Filament v3 widget that you can use to get an overview of all pausable jobs, and easily pause and resume them. Find more information in examples/FilamentWidgetExample. Here's what it looks like:
Requirements
- PHP 8.1+
- Laravel 10+
- Redis (optional)
License
MIT License (MIT). Please see License File for more information.
Support me
If you've found this package useful and want to support my work, feel free to look at purchasing one of my paid products listed on lostdomain.org. You can also find me on Bluesky 😊
