johnroyer/php-job-runner

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

This package is auto-updated.

Last update: 2024-09-28 17:23:05 UTC


README

这是一个简单的工具,可以帮助您执行常规任务。

示例

创建一个继承自 AbstractJob 的任务

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

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

将您的任务注册到运行器

$runner = new JobRunner\Runner();

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

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

通过 Linux crontab 触发运行器

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

待办事项

有待改进之处

  • 任务日志/通知器
  • 支持每周只运行一次的任务
  • 将阻塞/冲突其他任务的作业
  • 更好的时间/常规描述

许可证

  • MIT 许可证