Giter Site home page Giter Site logo

jobby's Introduction

Build Status

Jobby is a PHP cron job manager. 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.

Install

  1. Install composer.
  2. Add jobby to your composer.json.

'hellogerard/jobby': 'dev-master'

  1. Run composer install.
  2. 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 jobby file to the project root.

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

Usage

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)

Currently Supported Options

Global options can be given to the Jobby object constructor. These will be used as a default for all subsequent jobs. Individual jobs can override a particular option when the job is added.

Option         | Default                             | Required | Description
===============+=====================================+==========+============
               |                                     |          |
recipients     | null                                | No       | Comma-separated string of email addresses
mailer         | sendmail                            | No       | Email method: sendmail or smtp or mail
smtpHost       | null                                | No       | SMTP host, if `mailer` is smtp
smtpPort       | 25                                  | No       | SMTP port, if `mailer` is smtp
smtpUsername   | null                                | No       | SMTP user, if `mailer` is smtp
smtpPassword   | null                                | No       | SMTP password, if `mailer` is smtp
smtpSecurity   | null                                | No       | SMTP security option (ssl|tls), if `mailer` is smtp
smtpSender     | jobby@<hostname>                    | No       | The sender and from addresses used in SMTP notices
smtpSenderName | Jobby                               | No       | The name used in the from field for SMTP messages
runAs          | null                                | No       | Run as this user, if crontab user has `sudo` privileges
environment    | null or `getenv('APPLICATION_ENV')` | No       | Development environment for this job
runOnHost      | `gethostname()`                     | No       | Run jobs only on this hostname
maxRuntime     | null                                | No       | Maximum execution time for this job (in seconds)
output         | /dev/null                           | No       | Redirect `stdout` and `stderr` to this file
dateFormat     | 'Y-m-d H:i:s'                       | No       | Format for dates on `jobby` log messages
enabled        | true                                | No       | Run this job at scheduled times
haltDir        | null                                | No       | A job will not run if this directory contains a file bearing the job's name
debug          | false                               | No       | Send `jobby` internal messages to 'debug.log'
command        | none                                | Yes      | The job to run (either a shell command or anonymous PHP function)
schedule       | none                                | Yes      | Crontab schedule format (`man -s 5 crontab`)

Example jobby.php File

<?php 

require(__DIR__ . '/vendor/autoload.php');

$jobby = new \Jobby\Jobby();

// Every job has a name
$jobby->add('CommandExample', array(
    // Commands are either shell commands or anonymous functions
    'command' => 'ls',

    // Ordinary crontab schedule format is supported. This schedule runs every
    // hour
    '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', array(
    // Commands can be PHP closures
    'command' => function() {
        echo "I'm a function!\n";
        return true;
    },

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

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

$jobby->run();

Credits

Developed before, but since inspired by whenever.

Support via Gittip

jobby's People

Contributors

alexeymorozov avatar bitdeli-chef avatar fire015 avatar gbecchio avatar hellogerard avatar jdurand avatar kasp3r avatar kbariotis avatar kusmierz avatar llwt avatar loginwashere avatar mstraczkowski avatar simasgodovan avatar stricte avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.