Skip to content

job-runner/job-runner

Repository files navigation

JobRunner

Build Status Type Coverage Type Coverage Latest Stable Version License

Install

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 of exec
  • It lock by task and not for all task
  • It has an event manager

Simple Sample

<?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' => '* * * * *',
    ]
]));

Using you own locker storage

<?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);

Listening to events

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

Plugins