Solver.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Db;
  10. /**
  11. * 主要处理短信的命令行程序
  12. */
  13. class Solver extends Command {
  14. protected function configure() {
  15. // 指令配置
  16. $this->setName('solver')
  17. ->setDescription('the solver command');
  18. }
  19. protected function execute(Input $input, Output $output) {
  20. // 指令输出
  21. $lockFileName = "task_solver.lock";
  22. $lockFile = fopen($lockFileName, "a");
  23. if (flock($lockFile, LOCK_EX | LOCK_NB)) {//文件锁(独占)
  24. set_time_limit(0);
  25. $schedules = Db::table("new_schedule")->select();
  26. foreach ($schedules as $schedule) {
  27. //检查时间到了没
  28. if ($this->checkTime($schedule["time"])) {
  29. queue("app\job\Messenger", []); //任务加入队列待执行
  30. }
  31. }
  32. flock($lockFile, LOCK_UN);
  33. } else {
  34. $output->writeln('每分钟执行一次,执行时间超过1分钟下个1分钟跳过等待再下1分钟');
  35. }
  36. }
  37. private function checkTime() {
  38. return false;
  39. }
  40. }