Queue.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. use think\facade\Cache;
  11. class Queue extends Command
  12. {
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('queue')
  17. ->setDescription('the queue command');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $redis = Cache::store("redis");
  22. $jobHandlerClassName = 'app\Admin\JobInv@fire';
  23. //业务数据 对象需要手
  24. //动转序列化
  25. $invoce_tab = $redis->get("invoce_tab");
  26. if($invoce_tab==0){
  27. $redis->set("invoce_tab",1,1200);
  28. }else{
  29. return;
  30. }
  31. $jobQueueName = "createOrderJob1";
  32. $list=Db::name("invoice_img")->where([["status","=",1],["is_del","=",0],['crontab',"=",0]])->select();
  33. foreach ($list as $key=>$value){
  34. //入队列,later延时发送,单位秒。push立即发送
  35. $isPushed = $redis->handler()->lPush($jobQueueName, json_encode($value));
  36. if( $isPushed !== false ){
  37. Db::name("invoice_img")->where("id","=",$value['id'])->save(['crontab'=>1]);
  38. echo "执行成功";
  39. }else{
  40. echo '执行失败';
  41. }
  42. }
  43. $redis->set("invoce_tab",0);
  44. // $this->Jobdo();
  45. $output->writeln('queue');
  46. }
  47. }