composer require job-runner/job-runner
This cron job manager is inspired by https://github.com/jobbyphp/jobby but with various improvements
- It use
symfony/locker
so you can use the power of it - It use
symfony/process
instead ofexec
- It lock by task and not for all task
- It has an event manager
<?php
declare(strict_types=1);
use JobRunner\JobRunner\Job\CliJob;
use JobRunner\JobRunner\Job\JobList;
use JobRunner\JobRunner\CronJobRunner;
require 'vendor/autoload.php';
$jobList = new JobList();
$jobList->push(new CliJob('php ' . __DIR__ . '/tutu.php', '* * * * *'));
$jobList->push(new CliJob('php ' . __DIR__ . '/tutu2.php', '* * * * *'));
CronJobRunner::create()->run($jobList);
// or
CronJobRunner::create()->run(JobList::fromArray([
[
'command' => 'php ' . __DIR__ . '/tutu.php',
'cronExpression' => '* * * * *',
],[
[
'command' => 'php ' . __DIR__ . '/tutu2.php',
'cronExpression' => '* * * * *',
]
]));
<?php
declare(strict_types=1);
use JobRunner\JobRunner\Job\CliJob;
use JobRunner\JobRunner\Job\JobList;
use JobRunner\JobRunner\CronJobRunner;
require 'vendor/autoload.php';
$mySymfonyLockerStore = new \Symfony\Component\Lock\Store\MongoDbStore();
$jobList = new JobList();
$jobList->push(new CliJob('php ' . __DIR__ . '/tutu.php', '* * * * *'));
CronJobRunner::create()->withPersistingStore($mySymfonyLockerStore)->run($jobList);
there is various of event you can listen
JobRunner\JobRunner\Event\JobSuccessEvent
JobRunner\JobRunner\Event\JobFailEvent
JobRunner\JobRunner\Event\JobIsLockedEvent
JobRunner\JobRunner\Event\JobNotDueEvent
JobRunner\JobRunner\Event\JobStartEvent
- job-runner/psr-log-adapter Adapter to logs events in psr/log
- job-runner/symfony-console-adapter Adapter to logs events in symfony/console
- job-runner/symfony-notifier-adapter Adapter to logs events in symfony/notifier