Skip to content

Feat/task scheduler - #127

Merged
benkhalife merged 2 commits into
masterfrom
feat/task-scheduler
Sep 19, 2026
Merged

benkhalife merged 2 commits into
masterfrom
feat/task-scheduler

Conversation

@benkhalife

Copy link
Copy Markdown
Member

No description provided.

…heduleLock)

Adds a Laravel-scheduler-style API for running tasks on a fixed
interval, designed to work with webrium's plugin system rather than a
single hand-edited schedule file:

- ScheduleEvent: fluent builder (everyFiveMinutes(), dailyAt(), cron(),
  ...) wrapping a callback (closure, [class, method], or 'Class@method').
- CronExpression: minimal 5-field cron matcher (*, steps, ranges, lists)
  backing the fluent helpers.
- Schedule: static registry (call()/all()/reset()) plus
  loadFromDirectory(), which requires every *.php file under a directory
  recursively (so a plugin can drop its own task file into a
  subdirectory without touching anyone else's file), isolating each
  file's own load error so one broken file can't stop the rest from
  registering. runDue() then runs whichever registered tasks are due,
  isolating each task's execution the same way — a failing task is
  reported via Debug::triggerError and never stops the others.
- ScheduleLock: flock-based per-task lock preventing a still-running
  task from being started again by the next scheduler tick (single
  server; a shared, multi-server lock is intentionally left for later).

Two new Directory aliases: 'schedules' (app/Schedules) and
'schedule_locks' (storage/framework/schedule-locks).

The webrium/console counterpart (make:schedule, schedule:run) drives
this from a single system cron entry, mirroring Laravel's scheduler.
Support for on-demand tooling (webrium/console's schedule:list and
schedule:test) on top of the scheduler added in the previous commit:

- CronExpression::nextRunDate() / ScheduleEvent::nextRunDate(): the
  next minute (strictly after a given reference instant, default now)
  the expression is due, minute-resolution, capped at ~2 years lookahead
  so a self-contradictory expression can't loop unbounded.
- Schedule::find(): look up a registered task by its name.
- Schedule::run(): run a single task immediately, bypassing its own
  due-check, while still going through the same overlap lock and error
  isolation as runDue() (runOne() is folded into this, now public, as
  runDue() itself uses it per due task).
@benkhalife
benkhalife merged commit 4aaba01 into master Sep 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant