overnaive/think-swoole-crontab

基于 think-swoole 的 crontab 组件。

v0.1.0 2020-12-17 15:22 UTC

This package is auto-updated.

Last update: 2024-09-17 23:38:22 UTC


README

基于 think-swoole 的 crontab 组件。

声明

核心逻辑来自 Hyperfhyperf/crontab 组件。非常感谢 Hyperf 为大家提供了如此优秀的组件。

本组件尝试使其在 ThinkPHP 中运行(需结合 think-swoole 组件)。

目前仍处于初步可用阶段,后续会逐渐完善。

需求

安装

composer require overnaive/think-swoole-crontab

文档

用法

  1. event.php 中为 swoole.init 事件添加监听类。
return [
...
    'listem' => [
        ...
        'swoole.init' => [
            ...
            \ThinkSwooleCrontab\Process\CrontabDispatcherProcess::class,
            ...
        ],
        ...
    ],
...
];
  1. 在配置文件 crontab.php 中添加 \ThinkSwooleCrontab\Crontab 实例。
return [
    'crontab' => [
        (new \ThinkSwooleCrontab\Crontab())->setName('test-1')
            ->setRule('* * * * * *')
            ->setCallback([Test::class, 'run'])
            ->setMemo('just a test crontab'),
        (new \ThinkSwooleCrontab\Crontab())->setName('test-2')
            ->setRule('* * * * * *')
            ->setCallback([Test::class, 'run'])
            ->setMemo('just another test crontab'),
    ],
];

许可证

MIT