A simple tool to help you execute routine jobs.
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
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
- MIT license