johnroyer/php-job-runner

v1.1.2 2017-05-25 04:05 UTC

This package is auto-updated.

Last update: 2024-04-28 16:30:09 UTC


README

A simple tool to help you execute routine jobs.

Example

Create a job extends from AbstractJob:

class Cleanner extends \JobRunner\AbstractJob
{
    private $jobId = 'clean-outdated-backup';
    private $runTime = '0 3 * * *';

    public function update(\SplSubject $runner)
    {
        // clean outdated backups
    }
}

Register your job to runner:

$runner = new JobRunner\Runner();

$runner->attach(new Cleanner);
$runner->attach(new SomeOtherJob);
// ...

$runner->notify();  // runner will notify job which should run at current time

trigger runner by Linux crontab:

$ crontab -e
*/1 * * * *        /usr/bin/php  /path/to/bin/runner.php 2>&1 >/dev/null   // check jobs every minutes

TODO

there is something to improvent:

  • job logger / notifier
  • support jobs run only once in a week
  • job which will block / conflict other jobs
  • better time / routine descreption

License

  • MIT license