Search by

hydrakit / scheduler

whleucka

Scheduled work from one cron entry: due checks, overlap locks and bounded batches.

v0.24.0 2026-10-02 15:42 UTC

README

Part of the Hydra PHP framework. Documentation: hydra.williamhleucka.com/docs.

Read-only mirror. hydrakit/scheduler is developed in hydra-foundation/hydra under packages/scheduler, and republished here on every push. A commit pushed to this repository is overwritten by the next one; issues are disabled for that reason, and a pull request opened here cannot be merged. Both belong upstream.

Scheduled work from one cron entry. The application declares what runs and when on a Schedule: run() for a TaskInterface that does its work once, drain() for a BatchInterface that handles a capped batch and reports how many it did, and is called again until it reports none or its time budget is spent. Frequencies are everyMinute(), hourly(), dailyAt('04:00'), weekly() or a five-field cron() expression, read in the schedule's own zone rather than the clock's.

One cron entry runs it: * * * * * php bin/console schedule:run. Each task holds a flock() lock while it runs, so the kernel releases it however the run ends and a crash cannot lock a task out. A run still holding its lock is never started again beside it; once it has held the lock past warnAfter() minutes (an hour by default) every tick logs a warning instead. Due tasks run one after another in the order declared, so a long drain() belongs at the end.

SchedulerServiceProvider binds an empty Schedule for the application to fill from its own provider's boot(). Times are read in SCHEDULE_TIMEZONE, else APP_TIMEZONE, else UTC; locks live wherever the provider is told unless SCHEDULE_LOCK_DIR moves them.

Each run a tick makes is handed to a RunLogInterface: when it started, how long it took, what a batch handled, and the exception's class and message when it failed. The default keeps nothing. DatabaseRunLog keeps them in a scheduled_runs table, and latest() gives the newest run of each task. A run log that fails is logged as a warning; it never stops a task. Schedule PruneScheduledRuns daily to keep the table to SCHEDULE_KEEP_DAYS (7 by default).