<?php
namespace app\admin\command;

use app\task\Kernel;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * Thinkphp5 使用命令行模式(cli模式)
 * 定时任务
 * 执行命令:php think TimedTask
 * Author: Panda joeyoung0314@qq.com
 * Gitee:https://gitee.com/xertao
 */
class TimedTask extends Command
{
    protected function configure()
    {
        $this->setName('TimedTask')->setDescription('Here is the remark ');
    }

    // 业务代码 业务代码执行时间过长,会造成堵塞,请合理安排执行任务
    protected function execute(Input $input, Output $output)
    {
        $output->writeln("TimedTaskCommand:");

        while (true){
            $start_time = time();

            // 每分钟执行一次
            if (($start_time % 60) === 0){
                // 执行业务层
                (new Kernel())->schedule();
            }

            sleep(1);
        }
    }
}