norbybaru / easypeasy-runner
background jobs, independent of Laravel's built-in queue system
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- symfony/process: ^6.0|^7.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0|^11.0
README
Background Job Runner
A tailored custom system to execute PHP classes as background jobs, independent of Laravel's built-in queue system.
Feature
- Priority queue
- Retry attempt
- Delay process
- Retry failed jobs
Installation
composer require norbybaru/easypeasy-runner
Publish configuration
php artisan vendor:publish --tag="easypeasy-runner-config"
Publish migration
php artisan vendor:publish --tag="easypeasy-runner-migration"
Run migration
php artisan migrate
Usage
Configure Whitelist class namespaces
To prevent execution of unauthorized classes, you should update config/easypeasy-runner.php
file
with allowed class namespace or fully qualified class name.
eg.
<?php return [ .... 'allowed_namespaces' => [ 'App\\Services\\' ], ... ]
Start background process
Run the following artisan command to start processing background job
php artisan background:jobs:process
Basic
<?php use App\Services\EmailService; use function NorbyBaru\EasyRunner\runBackgroundJob; runBackgroundJob( className: EmailService::class, methodName: 'sendNotification', params: [ 'user@example.com', 'Welcome', 'This is welcome message' ] );
PS. Ensure to set params value in correct orders as in function definition eg.
<?php class EmailService { public function sendNotification(string $email, string $subject, string $message) { // Execute } }
Advanced
Configure priority job
Available options: low
, medium
, high
<?php use function NorbyBaru\EasyRunner\runBackgroundJob; runBackgroundJob( className: EmailService::class, methodName: 'sendUrgentNotification', params: [ 'user@example.com', 'Emergency Alert' ], options: [ 'priority' => 'high' ] );
Configure delay (seconds) job
<?php use function NorbyBaru\EasyRunner\runBackgroundJob; runBackgroundJob( className: EmailService::class, methodName: 'sendUrgentNotification', params: [ 'user@example.com', 'Emergency Alert' ], options: [ 'priority' => 'low', 'delay' => 120 ] );
Override Retry configuration
<?php use App\Services\ReportGenerator; use function NorbyBaru\EasyRunner\runBackgroundJob; runBackgroundJob( className: ReportGenerator::class, methodName: 'generateMonthlyReport', params: [ '2023-11' ], options: [ 'retry_attempts' => 5 ] );
Monitoring
View info logs
New file are generated daily with date format background_jobs-YYY-MM-DD
.
eg. background_jobs-2024-11-23.log
.
tail -f background_jobs-2024-11-23.log
View Error logs
New file are generated daily with date format background_jobs_errors-YYY-MM-DD
.
eg. background_jobs_errors-2024-11-23.log
.
tail -f background_jobs_errors-2024-11-23.log
Cleanup Jobs table
php artisan background:jobs:cleanup
Jobs Stats
Display Background Jobs Stats
php artisan background:jobs:stats
Live update of Background Jobs Stats
php artisan background:jobs:stats --live
Display only failed Jobs
php artisan background:jobs:stats --failed
Retry Failed Jobs
Retry all failed jobs
php artisan background:jobs:retry-failed
Retry a single failed job
php artisan background:jobs:retry-failed --id={jobID}