rkr / service-dispatcher
0.3.8.1
2022-08-24 18:47 UTC
Requires
- php: >= 7.1
- ext-pdo: *
- dragonmantank/cron-expression: >= 3
- psr/log: >= 1.0
- rkr/php-ioc-contract: ~0.1@stable
Requires (Dev)
- phpstan/phpstan: >= 0.1
- phpunit/phpunit: >=7 <9
README
Common usage using SQLite
A simple service dispatcher for shell scripts. The intent is to run a php-cli script every minute and let the script decide, what to run at what time...
use Kir\Services\Cmd\Dispatcher\Dispatcher; require __DIR__ . '/vendor/autoload.php'; use Kir\Services\Cmd\Dispatcher\ServiceDispatcherBuilder; $dispatcher = ServiceDispatcherBuilder::withSQLite(__DIR__.'/services.db')->build(); $dispatcher->register('service1', Dispatcher::ONE_HOUR, function () { // Do something throw new Exception(); }); $dispatcher->register('service2', Dispatcher::ONE_HOUR * 3, function () { // Do something }); $dispatcher->run();
The example above show the simplest usage of the service dispatcher. Two services get registered. "Service1" and "Service2". If one service throws an exception, the whole execution stops. Next time, the failed service starts at the end of the queue. If a service was successfully executed, the timeout schedules the service in this case to 1 hour (3600 seconds) in the future.
MySQL-Specific settings:
use Kir\Services\Cmd\Dispatcher\ServiceDispatcherBuilder; require __DIR__ . '/vendor/autoload.php'; /* ... */ $dispatcher = ServiceDispatcherBuilder::withMySQL($pdo) ->useLocking(true) ->setLockPrefix('my-app:') ->build(); $dispatcher->register(/*...*/); /* ... */