12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\model\TaxiChauffeur;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- class Task extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('task')
- //增加一个命令参数
- ->addArgument('action', Argument::OPTIONAL, "action", '')
- ->addArgument('force', Argument::OPTIONAL, "force", '');
- }
- protected function execute(Input $input, Output $output)
- {
- //获取输入参数
- $action = trim($input->getArgument('action'));
- $force = trim($input->getArgument('force'));
- $task = new \EasyTask\Task();
- $task->setDaemon(true);
- //$task->setPrefix('task_test');
- $task->setRunTimePath('./runtime/');
- // 配置任务,开启1个进程每隔10秒进行一次
- $task->addFunc(function () {
- (new TaxiChauffeur())->getChauffeurData();
- }, 'data_save', 30, 1);
- // 根据命令执行
- if ($action == 'start') {
- $task->start();
- } elseif ($action == 'status') {
- $task->status();
- } elseif ($action == 'stop') {
- $force = ($force == 'force'); //是否强制停止
- $task->stop($force);
- } else {
- exit('Command is not exist');
- }
- }
- }
|