snanword / task_tools
定时任务管理工具
v1.1
2020-04-25 08:40 UTC
Requires
- php: >=5.6
- predis/predis: ^1.1
- yzalis/crontab: ^1.0
This package is auto-updated.
Last update: 2024-09-16 04:06:50 UTC
README
## 轻量级定时任务管理工具
.env 配置文件
[TASK_CONFIG] //Whether the command line outputs error messages
DEAMON = false
TASK_NAMESPACE = '\SnanWord\TaskTool\task\' settion your task namespace
MODE = 'think' //If thinkphp class library is used in the task, please add this item, otherwise do not add
[REDIS] //redis configuration file
host = 127.0.0.1
password = 'sxsaio!2js'
port = 23904
database = 1
[TASK_LIST] //All tasks must be added to this configuration item in this format
auto_receipt_task = 1
test_task => 0
创建任务
1: 编写任务代码
<?php namespace SnanWord\TaskTool\task; use SnanWord\TaskTool\basis\TaskAbstract; class AutoReceiptTask extends TaskAbstract { /** * run * @des task run code * @return mixed|void * @author Snan */ public function run() { // TODO: Implement run() method. var_dump('hello-word'); } /** * setCrontab * @des setting crontab rule * @return array * @author Snan */ public function setCrontab() { return ['*','0','*','*','*'];//[Minute, hour, day, month, week] } }
2: 在命令行中输入以下命令进行初始化
php vendor/snanword/task_tools/src/bin/snantask.php init
After the initialization is complete, the snantask.php file will be generated in the root directory of your project
3: 启动任务
php snantask.php start
task test_task is not started
Task list status:
| task_name:auto_receipt_task| task_class:\SnanWord\TaskTool\task\AutoReceiptTask| status:run
| task_name:test_task| status:stop
success
4: 添加任务 任务也可以在启动任务后交付
Add your new task under the TASK_LIST configuration in the .env file, and then execute the following command
php snantask.php add {Your new task}
5: 关闭任务
php snantask.php stop //Close all
php snantask.php stop {your task} //Close one
6: 显示列表
php snantask.php list
Task list status:
| task_name:auto_receipt_task| task_class:\SnanWord\TaskTool\task\AutoReceiptTask| status:run
| task_name:test_task| status:stop
success