spatie/laravel-short-schedule
Run Laravel Artisan commands at sub-minute intervals (every second or even 0.5s). Adds a short-scheduler powered by a ReactPHP event loop, running separately from schedule:run so high-frequency tasks don’t block or get delayed.
Symfony\Component\Process), preventing memory leaks or slow tasks from impacting the scheduler’s performance.when(), between(), environments(), and onOneServer() constraints, enabling fine-grained control over task execution (e.g., time-based throttling, environment-specific runs).Console/Kernel.php and routes/console.php.ShortSchedule) and a kernel method (shortSchedule()), offering flexibility in how schedules are defined.ShortSchedule::exec('bash-script')->everySecond()), broadening use cases beyond Artisan commands.ShortScheduledTaskStarting and ShortScheduledTaskStarted events, enabling observability and side effects (e.g., logging, metrics).everySeconds(0.5)), system clock skew or OS scheduling latency may introduce variability in actual execution timing.--lifetime flag to avoid memory bloat (e.g., php artisan short-schedule:run --lifetime=60).when() closures or event listeners run in the loop, so slow logic will delay all scheduled tasks. Offload heavy work to queues.everyMinute + delay) suffice?when() conditions)? If so, how will this be mitigated (e.g., queue-based constraints)?onOneServer() conflicts be handled?when() + between())?schedule:run without duplication.ShortSchedule::command()) for simplicity.shortSchedule() method in Console/Kernel.php for better organization.when(), between()) based on need.ShortScheduledTaskStarting) and metrics (e.g., execution latency).schedule:run). Runs as a separate process.composer require spatie/laravel-short-schedule
routes/console.php or Console/Kernel.php:
protected function shortSchedule(ShortSchedule $shortSchedule) {
$shortSchedule->command('optimize:clear')->everySecond();
}
/etc/supervisor/conf.d/short-schedule.conf):
[program:laravel-short-schedule]
command=php /path/to/artisan short-schedule:run --lifetime=60
autostart=true
autorestart=true
user=www-data
numprocs=1
supervisorctl reread
supervisorctl update
supervisorctl start laravel-short-schedule
tail -f /path/to/storage/logs/laravel.log
when(), between()) in staging.--lifetime to auto-restart workers and prevent memory leaks (e.g., --lifetime=3600 for hourly restarts).ShortScheduledTaskStarting) for observability.everySeconds(1) and measure actual execution times (may vary due to OS scheduling).when() closures to ensure they execute <100ms.schedule:run (native) and short-schedule:run are both running.www-data) has access to command paths.onOneServer() to prevent duplicate runs across multiple workers.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Worker process crashes | Missed tasks | Supervisor auto-restart + alerts |
| Memory leak in long-running task | OOM kill | --lifetime flag + monitoring |
Slow when() constraint |
Delayed tasks | Offload to queue + optimize constraint logic |
| Database connection exhaustion | Task failures |
How can I help you explore Laravel packages today?