kinetis / scheduler
Recurring jobs and commands for Kinetis, declared with #[Schedule] — each due slot is claimed once in MySQL/Postgres and enqueued at least once for the existing queue worker, exactly once with kinetis/queue-sql.
Requires
- php: >=8.4 <8.6
- dragonmantank/cron-expression: ^3.6.1
- kinetis/database-bridge: ^1.4.8
- kinetis/framework: ^1.32.1
- kinetis/persistence: ^1.5.1
- kinetis/queue: ^1.10.4
- psr/log: ^3.0.2
Requires (Dev)
- infection/infection: ^0.35.15
- kinetis/migrations: ^1.5.2
- kinetis/queue-sql: ^1.6.14
- phpstan/phpstan: ^2.2.8
- phpunit/phpunit: ^13.3.3
- vimeo/psalm: ^7.24.1
Suggests
- ext-pcntl: Lets `kinetis schedule:work` stop gracefully on SIGTERM between ticks instead of being killed mid-claim. Not loaded by default in the official PHP Docker images.
- kinetis/queue-sql: Enqueues each slot in the same transaction that claims it, so a due slot is enqueued exactly once.
Provides
None
Conflicts
- kinetis/queue-sql: <1.4.0
Replaces
None
README
kinetis/scheduler
Recurring jobs and commands declared with #[Schedule], each slot claimed once and run by the queue worker
Part of Kinetis, a non-blocking PHP framework for API-first applications, developed in the kinetis-dev/kinetis monorepo.
Runs jobs and commands on a recurring schedule declared in code. The
scheduler claims each due slot once in a MySQL or Postgres table and
pushes a job for it onto kinetis/queue,
where the existing queue:work worker runs it. Any number of scheduler
replicas can run side by side.
use Kinetis\Scheduler\Attributes\Schedule; #[Schedule(cron: '0 3 * * *', command: 'session:gc')] #[Schedule(everySeconds: 30, command: 'app:sync-prices')] final class Schedules { }
vendor/bin/kinetis schedule:work # claim and enqueue due slots every second vendor/bin/kinetis schedule:run # one pass, for an external timer every minute vendor/bin/kinetis schedule:list # every entry and its next due time
On a class implementing Kinetis\Queue\Job, #[Schedule] schedules that
job, with arguments as its named constructor arguments.
The claims need a table
Copy the stub matching the default database connection into your
kinetis/migrations
migrations/ directory with a timestamp prefix, and run
vendor/bin/kinetis migrate:
vendor/kinetis/scheduler/resources/migrations/create_kinetis_schedule_claims_table.mysql.php.stub
vendor/kinetis/scheduler/resources/migrations/create_kinetis_schedule_claims_table.pgsql.php.stub
Delivery
A due slot is enqueued at least once, and exactly once with
kinetis/queue-sql; the job
then runs at least once. A slot not claimed within 60 seconds is dropped
and never caught up. See
kinetis.dev/docs/scheduler.html.
Installation
composer require kinetis/scheduler
Requires PHP 8.4 or 8.5, kinetis/framework,
kinetis/queue,
kinetis/persistence,
kinetis/database-bridge and
dragonmantank/cron-expression.
Full documentation:
kinetis.dev/docs/scheduler.html.
License
MIT — see LICENSE.