mj-zana / scheduler
Scheduled tasks for Zana applications: cron expressions, a scope per run, overlap locks and schedule:run
v2.5.0
2026-10-26 14:55 UTC
Requires
- php: ^8.5
- mj-zana/console: ^2.2
- mj-zana/core: ^2.4
- psr/log: ^3.0
- psr/simple-cache: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Scheduled tasks for Zana applications: cron expressions, a container scope
per run, overlap locks, and schedule:run.
composer require mj-zana/scheduler
Register SchedulerServiceProvider (with ConsoleServiceProvider), add
tasks in a provider's or module's boot(), and run the scheduler every
minute from the system's crontab:
$schedule = $container->get(Schedule::class); $schedule->call(PublishDuePosts::class)->everyMinute()->withoutOverlapping(); $schedule->call([Reports::class, 'weekly'])->cron('0 7 * * mon')->timezone('Africa/Kinshasa');
* * * * * cd /var/www/app && php bin/zana schedule:run >> var/log/schedule.log 2>&1
Rules
- What a task can be: a closure, an invokable class or
[class, method]. Its parameters are resolved from a fresh container scope for each run. - Failures: a failing task is logged (PSR-3) and does not stop the
others.
schedule:runthen exits with 1. - Cron expressions have five fields, with lists, ranges, steps and names,
plus
@daily-style aliases. Shortcuts:everyMinute(),hourly(),dailyAt('03:00'),weekly(),monthly(). - Overlap:
withoutOverlapping()skips a run while the previous one holds its lock, using the PSR-16 cache. - Listing:
schedule:listshows every task and its next run.
License
MIT