ExecPush.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;use think\facade\Db;
  10. class ExecPush extends Command
  11. {
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('execpush')
  16. ->setDescription('the execpush command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. $key = Cache::store("redis")->handler()->get("reportKey");
  21. if($key==1) return '';
  22. Cache::store("redis")->handler()->set("reportKey",1,180);
  23. $list =Db::name("exec_log")->where([["expiretime","<=",date("Y-m-d H:i:s")],["status","=",1],["is_del","=",
  24. 0]])->select()->toArray();
  25. if(!empty($list)){
  26. foreach ($list as $value){
  27. Cache::store("redis")->handler()->lpush("Reportexec",json_encode($value,JSON_UNESCAPED_UNICODE));
  28. Db::name("exec_log")->where($value)->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
  29. $date=date("Y-m-d H:i:s");
  30. $output->writeln("[{$date}] 脚本记录{$value['id']}放入待执行中");
  31. }
  32. }
  33. Cache::store("redis")->handler()->set("reportKey",0);
  34. }
  35. }