yzh52521 / think-swoole-crontab
crontab 组件 think-swoole。
v1.0.7
2023-09-14 07:15 UTC
Requires
- php: >=7.4
- nesbot/carbon: ^2.0
- symfony/console: ^5.3|^6.0
- topthink/think-swoole: ^4.0
README
声明
核心逻辑来自 Hyperf 的 hyperf/crontab 组件。非常感谢 Hyperf 为大家提供这么优秀的组件。
本组件尝试在 ThinkPHP 中运行(需要结合 think-swoole 组件)。
目前还处于初步可用阶段,后续会逐渐完善。
需求
- PHP >= 8.0
- Composer
安装
composer require yzh52521/think-swoole-crontab
文档
用法
- 在
event.php
中为swoole.init
事件添加监听类。
return [
...
'listen' => [
...
'swoole.init' => [
...
\ThinkCrontab\Process\CrontabDispatcherProcess::class,
...
],
...
],
...
];
- 在配置文件
crontab.php
中添加\ThinkCrontab\Crontab
实例。
return [
'crontab' => [
// Callback类型定时任务(默认)
(new \ThinkCrontab\Crontab())->setName('test-1')
->setRule('* * * * * *')
->setCallback([app\Task\FooTask::class, 'execute'])
->setMemo('just a test crontab'),
// Command类型定时任务
(new \ThinkCrontab\Crontab())->setType('command')->setName('test-2')
->setRule('* * * * * *')
->setCallback([
'command' => 'mailer:send',
// (optional) arguments
'arguments' => 'barValue'
]),
],
];
许可证
MIT