overnaive/think-swoole-crontab

A crontab component base on think-swoole.

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

This package is auto-updated.

Last update: 2025-03-18 00:36:37 UTC


README

A crontab component base on think-swoole.

声明

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

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

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

Requirement

Installation

composer require overnaive/think-swoole-crontab

Documents

Usage

  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'),
    ],
];

License

MIT