thhan/schedule-bundle

thhan ScheduleBundle

安装次数: 4

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2020-02-24 18:47 UTC

This package is auto-updated.

Last update: 2024-09-25 05:01:39 UTC


README

此包提供了一种通过简单函数将控制台命令添加到cron作业的功能。

安装

composer req thhan/schedule-bundle

手动注册此包。

// config/bundles.php

return [
    // Other bundles...
    Thhan\ScheduleBundle\ScheduleBundle::class => ['all' => true],
];

服务器配置

最后,您在服务器上创建一个cron作业,每分钟执行“schedule:run”命令。

* * * * * {path_to_symfony}/bin/console schedule:run >> /dev/null 2>&1

用法

将Trait Schedule类添加到您的控制台命令中。通过“addCron”函数扩展配置函数。作为参数,您传递一个字符串或字符串数组,格式为cron作业。

use Thhan\ScheduleBundle\Command\Schedule;

class YourCommand extends Command {
    use Schedule;

    public function configure() {
        $this->setName('app:test')
             ->addCron('30 3 * * *')
             ->addCron([
                 '*/10 * * * *',
                 '0 22 * * 1'
             ]);
    }
}

计划

  • 通过配置添加作业
  • 添加输出日志器