brzuchal / scheduler
Scheduling messages with recurring options
Installs: 1 055
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: 8.1.*
- ext-pdo: *
- brzuchal/recurrence-rules: 1.x-dev
- ramsey/uuid: ^4.3
Requires (Dev)
- doctrine/coding-standard: ^9.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.21
README
A message to Russian 🇷🇺 people
If you currently live in Russia, please read this message.
Purpose
Message Scheduler implements persistent storage for any kind of message objects for all the idle time before it actually should be dispatched for handling. Dispatching can happen at exact trigger time or using recurrence rule which determines a set of times when the execution mechanism trigger the message.
Install
composer require brzuchal/scheduler
Usage
use Brzuchal\Scheduler\Executor\SimpleScheduleExecutor; use Brzuchal\Scheduler\MessageScheduler; use Brzuchal\Scheduler\Store\PdoScheduleStore; $store = new PdoScheduleStore(new PDO('sqlite:scheduler.sqlite')); $scheduler = new MessageScheduler($store); $executor = new SimpleScheduleExecutor($store, var_dump(...)); // Scheduling message $scheduler->schedule(new DateTimeImmutable('tomorrow 09:00:00'), new \FooMessage()); // Execute all pending messages $dateTime = new DateTimeImmutable('now'); foreach ($store->findPendingSchedules($dateTime) as $identifier) { $executor->execute($identifier); }
Note! PDO store requires manual setup depending on database platform used. See schema.sql for example schema.
License
MIT License
Copyright (c) 2022 Michał Marcin Brzuchalski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.