jetfirephp/jobby

Manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.

dev-master 2016-12-14 14:46 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:36:16 UTC


README

Total Downloads Latest Version Build Status MIT License

Install the master jobby cron job, and it will manage all your offline tasks. Add jobs without modifying crontab. Jobby can handle logging, locking, error emails and more.

NEW REPO: We have moved jobby to a Github org. Please update your remotes to https://github.com/jobbyphp/jobby.git.

Features

  • Maintain one master crontab job.
  • Jobs run via PHP, so you can run them under any programmatic conditions.
  • Use ordinary crontab schedule syntax (powered by the excellent cron-expression).
  • Run only one copy of a job at a given time.
  • Send email whenever a job exits with an error status.
  • Run job as another user, if crontab user has sudo privileges.
  • Run only on certain hostnames (handy in webfarms).
  • Theoretical Windows support (but not ever tested)

Example

<?php 

require_once __DIR__ . '/vendor/autoload.php';

$jobby = new Jobby\Jobby();

// Every job has a name
$jobby->add('CommandExample', [
    // Run a shell commands
    'command'  => 'ls',

    // Ordinary crontab schedule format is supported.
    // This schedule runs every hour.
    // You could also insert DateTime string in the format of Y-m-d H:i:s.
    'schedule' => '0 * * * *',

    // Stdout and stderr is sent to the specified file
    'output'   => 'logs/command.log',

    // You can turn off a job by setting 'enabled' to false
    'enabled'  => true,
]);

$jobby->add('ClosureExample', [
    // Invoke PHP closures
    'closure'  => function() {
        echo "I'm a function!\n";
        return true;
    },

    // This function will run every other hour
    'schedule' => '0 */2 * * *',

    'output'   => 'logs/closure.log',
]);

$jobby->run();

Installation

The recommended way to install Jobby is through Composer:

$ composer require hellogerard/jobby

Then add the following line to your (or whomever's) crontab:

* * * * * cd /path/to/project && php jobby.php 1>> /dev/null 2>&1

After Jobby installs, you can copy an example file to the project root.

$ cp vendor/hellogerard/jobby/resources/jobby.php .

Supported Options

Each job requires these:

The options listed below can be applied to an individual job or globally through the Jobby constructor. Global options will be used as default values, and individual jobs can override them.

Credits

Developed before, but since inspired by whenever.

Support this project