david-garcia/php-resque-scheduler
PHP port of resque-scheduler for php-resque, adding delayed job scheduling. Enqueue jobs to run at a future timestamp or after N seconds, compatible with the Ruby resque-scheduler web UI. Recurring/cron-style jobs not yet supported.
Installation
composer require david-garcia/php-resque-scheduler
(Note: Due to the package being archived, verify compatibility with your PHP/Resque version.)
Basic Configuration
Add to your config/resque.php (or equivalent):
'scheduler' => [
'connection' => 'redis',
'queue' => 'scheduler',
'interval' => 60, // Seconds between checks
],
First Use Case: Scheduling a Job
use Resque\Job\Job;
use DavidGarcia\ResqueScheduler\Scheduler;
$scheduler = new Scheduler();
$scheduler->schedule(
new Job('queue:name', ['param1', 'param2']),
now()->addMinutes(5)
);
src/Scheduler.php for core logic.tests/ for usage examples (if any).Cron-Like Scheduling Replace cron jobs with PHP-based scheduling:
$scheduler->schedule(
new Job('process:invoices', ['user_id' => 123]),
now()->addHour()
);
Recurring Jobs Use a loop to reschedule:
$job = new Job('sync:data', []);
$scheduler->schedule($job, now()->addMinutes(30));
// Inside the job's `perform()`:
$scheduler->schedule($job, now()->addMinutes(30));
Dynamic Queues Route jobs to different queues based on conditions:
$queue = $user->isPremium() ? 'premium' : 'standard';
$scheduler->schedule(new Job("{$queue}:process", [...]), now());
Laravel Integration:
Use Laravel’s Artisan::queue() to wrap jobs:
$scheduler->schedule(
new Job('laravel:artisan', ['command' => 'queue:work']),
now()->addSecond(10)
);
Resque Worker Setup:
Ensure your Resque worker processes the scheduler queue:
resque -q scheduler,default
Logging:
Extend Scheduler to log scheduled jobs:
$scheduler->schedule($job, $time, function () {
Log::info("Scheduled job {$job->getClass()}");
});
Redis Connection Issues
Redis::connection()->ping();
config/resque.php.Timezone Mismatches
app.php or use Carbon:
$scheduler->schedule($job, Carbon::now('UTC')->addMinutes(5));
Missing Dependencies
chrisboulton/php-resque).composer require chrisboulton/php-resque
Archived Package Risks
spatie/laravel-scheduler.$scheduledJobs = Redis::connection()->lrange('resque:scheduler', 0, -1);
resque -v -q scheduler
# docker-compose.yml
services:
redis:
image: redis
ports: ["6379:6379"]
Custom Storage
Override getStorageKey() in Scheduler to use a custom Redis key.
Job Validation Add pre-schedule validation:
$scheduler->beforeSchedule(function (Job $job) {
if (!$job->isValid()) {
throw new \RuntimeException("Invalid job");
}
});
Event Listeners Trigger events before/after scheduling:
$scheduler->onSchedule(function (Job $job, \DateTime $time) {
event(new JobScheduled($job, $time));
});
How can I help you explore Laravel packages today?