abc / scheduler
Library for to manage schedules for repeated execution of tasks
Installs: 3 876
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- php: ^7.2
- dragonmantank/cron-expression: ^2.3
- myclabs/php-enum: ^1.7
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^8.0|^9.0
- symfony/console: ^4.3|^5.1
This package is not auto-updated.
Last update: 2024-12-11 15:13:26 UTC
README
A PHP library to process schedules base on CRON expressions.
Features:
- Define schedules based on CRON expressions
- Symfony Console Command to run scheduler
- Simple integration by implementing two interfaces
Note: This project is still experimental!
Installation
composer require abc/scheduler
Getting Started
-
Define a schedule provider by implementing
ProviderInterfacve
.namespace Abc\Scheduler; interface ProviderInterface { /** * @return string The provider's name, used to bind a provider to processors */ public function getName(): string; /** * @param int|null $limit * @param int|null $offset * @return ScheduleInterface[] */ public function provideSchedules(int $limit = null, int $offset = null): array; public function save(ScheduleInterface $schedule): void; }
-
Define a schedule processor by implementing
ProcessorInterface
.namespace Abc\Scheduler; /** * Process a schedule that is due. */ interface ProcessorInterface { public function process(ScheduleInterface $schedule); }
-
Bind Processor to Provider and initialize the ScheduleCommand
use Abc\Scheduler\Scheduler; use Abc\Scheduler\Symfony\ScheduleCommand; $myProvider = new MyProvider(); $myProcessor = new MyProcessor(); $scheduler = new Scheduler(); $scheduler->bind($myProvider, $myProcessor); $command = new ScheduleCommand($scheduler);
-
Run the command
bin/console abc:schedule
License
The MIT License (MIT). Please see License File for more information.