123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\facade\Cache;use think\facade\Db;
- class ExecPush extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('execpush')
- ->setDescription('the execpush command');
- }
- protected function execute(Input $input, Output $output)
- {
- $key = Cache::store("redis")->handler()->get("reportKey");
- if($key==1) return '';
- Cache::store("redis")->handler()->set("reportKey",1,180);
- $list =Db::name("exec_log")->where([["expiretime","<=",date("Y-m-d H:i:s")],["status","=",1],["is_del","=",
- 0]])->select()->toArray();
- if(!empty($list)){
- foreach ($list as $value){
- Cache::store("redis")->handler()->lpush("Reportexec",json_encode($value,JSON_UNESCAPED_UNICODE));
- Db::name("exec_log")->where($value)->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
- $date=date("Y-m-d H:i:s");
- $output->writeln("[{$date}] 脚本记录{$value['id']}放入待执行中");
- }
- }
- Cache::store("redis")->handler()->set("reportKey",0);
- }
- }
|