yzh52521/think-swoole-crontab

crontab component think-swoole.

v1.0.7 2023-09-14 07:15 UTC

This package is auto-updated.

Last update: 2024-04-14 08:42:38 UTC


README

声明

核心逻辑来自于 Hyperfhyperf/crontab 组件。非常感谢 Hyperf 为大家提供这么优的组件。

本组件试图让其运行在 ThinkPHP 里(需结合 think-swoole 组件)。

目前还处于初步可用阶段,后续会慢慢完善。

Requirement

Installation

composer require yzh52521/think-swoole-crontab

Documents

Usage

  1. event.php 里为 swoole.init 事件添加监听类。
return [
...
    'listen' => [
        ...
        'swoole.init' => [
            ...
            \ThinkCrontab\Process\CrontabDispatcherProcess::class,
            ...
        ],
        ...
    ],
...
];
  1. 在配置文件 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'
            ]),
    ],
];

License

MIT