infuse / cron
Infuse 框架的定时任务模块
2.1
2019-08-15 19:24 UTC
Requires
- php: >=7.1
- symfony/event-dispatcher: ^4.3
- symfony/lock: ^4.3
Requires (Dev)
- infuse/infuse: ~1.6
- mockery/mockery: ~1.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: 6.0.*
- pulsar/pulsar: ~0.9
- robmorgan/phinx: ~0.8
This package is auto-updated.
Last update: 2024-09-16 07:11:41 UTC
README
Infuse 框架的定时任务模块
安装
-
使用 composer 安装此包
composer require infuse/cron
-
将运行任务的控制台命令添加到应用程序配置中的
console.commands
'console' => [ // ... 'commands' => [ // ... 'Infuse\Cron\Console\RunScheduledCommand' ] ]
-
将迁移添加到应用程序配置
'modules' => [ 'migrations' => [ // ... 'Cron' ], 'migrationPaths' => [ // ... 'Cron' => 'vendor/infuse/cron/src/migrations' ] ]
-
将定时任务添加到应用程序配置的
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' ] ]
-
编写你的任务代码。每个任务类必须是 可调用的。
-
将以下内容添加到 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 兼容。