idealisticsoft/framework-cron

此包已废弃,不再维护。作者建议使用infuse/cron包代替。

Infuse框架的定时任务模块

2.1 2019-08-15 19:24 UTC

This package is auto-updated.

Last update: 2019-08-15 19:26:17 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads

Infuse框架的定时任务模块

安装

  1. 使用composer安装此包

    composer require infuse/cron
    
  2. 将执行任务的控制台命令添加到应用程序配置的console.commands

    'console' => [
       // ...
       'commands' => [
          // ...
          'Infuse\Cron\Console\RunScheduledCommand'
       ]
    ]
  3. 将迁移添加到应用程序配置

    'modules' => [
       'migrations' => [
          // ...
          'Cron'
       ],
       'migrationPaths' => [
          // ...
          'Cron' => 'vendor/infuse/cron/src/migrations'
       ]
    ]
  4. 将定时任务添加到应用程序配置的cron部分

    'cron' => [
       [
          'id' => 'users:cleanup',
          'class' => 'App\Users\ScheduledJobs\Cleanup',
          'minute' => 0,
          'hour' => 0,
          'expires' => 60,
          'successUrl' => 'https://webhook.example.com'
       ],
       [
          'id' => 'orgs:bill',
          'class' => 'App\Billing\ScheduledJobs\Bill'
       ]
    ]
  5. 编写你的任务代码。每个任务类必须是可以调用的

  6. 将此添加到你的crontab中,以便在后台运行应用程序的定时任务

    *	*	*	*	*	php /var/www/example.com/infuse cron:run

事件

您可以使用symfony/event-dispatcher组件中的事件订阅者来订阅事件。您的订阅者可以监听这些事件

  • schedule_run.begin
  • schedule_run.finished
  • cron_job.begin
  • cron_job.finished

当您创建了一个事件订阅者后,您可以将其添加到配置中,如下所示

'cronSubscribers' => [
    'App\EventSubscribers\MySubscriber'
]

Webhooks

您可以指定一个URL,在成功运行时将被调用。运行输出的结果可以通过m查询参数获得。此功能设计为与Dead Man's Snitch兼容。