hatimox / jobby
Manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.
Requires
- php: >=7.4
- alek13/slack: ^2.2
- dragonmantank/cron-expression: ^3.0
- opis/closure: ^3.5
- swiftmailer/swiftmailer: ^5.4|^6.0
- symfony/process: ^2.7|^3.0|^4.0|^5.0
Requires (Dev)
- mp091689/dump-die: ^1.0
- phpunit/phpunit: ^4.6
- symfony/filesystem: ^2.7|^3.0|^4.0|^5.0
- dev-master
- v3.6.2
- v3.6.1
- v3.6.0
- V3.5.2
- V3.5.1
- v3.5.0
- v3.4.7
- v3.4.6
- v3.4.5
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.0
- v2.1.0
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.0
- dev-update-dependencies
- dev-Fix-Logs
- dev-Logs_Optimizations
- dev-Develop
This package is auto-updated.
Last update: 2024-10-29 12:50:20 UTC
README
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.
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)
- Send alerts to Slack or Mattermost whenever a job exits with an error status.
Getting Started
Installation
The recommended way to install Jobby is through Composer:
$ composer require hatimox/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/hatimox/jobby/resources/jobby.php .
Running a job
<?php // Ensure you have included composer's autoloader require_once __DIR__ . '/vendor/autoload.php'; // Create a new instance of Jobby $jobby = new Jobby\Jobby(); // Every job has a name $jobby->add('CommandExample', [ // Run a shell command 'command' => 'ls', // Ordinary crontab schedule format is supported. // This schedule runs every hour. 'schedule' => '0 * * * *', ]); $jobby->run();
Examples
Logging
<?php /* ... */ $jobby->add('LoggingExample', [ 'command' => 'ls', 'schedule' => '0 * * * *', // Stdout and stderr is sent to the specified file 'output' => 'logs/command.log', ]); /* ... */
Disabling a command
<?php /* ... */ $jobby->add('DisabledExample', [ 'command' => 'ls', 'schedule' => '0 * * * *', // You can turn off a job by setting 'enabled' to false 'enabled' => false, ]); /* ... */
Running closures
When running closures, beware that nothing outside of the closure is visible (see #93)!
<?php /* ... */ $jobby->add('ClosureCommandExample', [ // Use the 'closure' key // instead of 'command' 'closure' => function() { echo "I'm a function!\n"; return true; }, 'schedule' => '0 * * * *', ]); /* ... */
Using a DateTime
<?php /* ... */ $jobby->add('DateTimeExample', [ 'command' => 'ls', // Use a DateTime string in // the format Y-m-d H:i:s 'schedule' => '2017-05-03 17:15:00', ]); /* ... */
Using a Custom Scheduler
<?php /* ... */ $jobby->add('Example', [ 'command' => 'ls', // Use any callable that returns // a boolean stating whether // to run the job or not 'schedule' => function(DateTimeImmutable $now) { // Run on even minutes return $now->format('i') % 2 === 0; }, ]); /* ... */
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.
Symfony integration
Symfony bundle for Jobby - imper86/jobby-cron-bundle
Credits
Developed before, but since inspired by whenever.