123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?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\Db;
- use think\facade\Cache;
- class Queue extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('queue')
- ->setDescription('the queue command');
- }
- protected function execute(Input $input, Output $output)
- {
- $redis = Cache::store("redis");
- $jobHandlerClassName = 'app\Admin\JobInv@fire';
- //业务数据 对象需要手
- //动转序列化
- $invoce_tab = $redis->get("invoce_tab");
- if($invoce_tab==0){
- $redis->set("invoce_tab",1,1200);
- }else{
- return;
- }
- $jobQueueName = "createOrderJob1";
- $list=Db::name("invoice_img")->where([["status","=",1],["is_del","=",0],['crontab',"=",0]])->select();
- foreach ($list as $key=>$value){
- //入队列,later延时发送,单位秒。push立即发送
- $isPushed = $redis->handler()->lPush($jobQueueName, json_encode($value));
- if( $isPushed !== false ){
- Db::name("invoice_img")->where("id","=",$value['id'])->save(['crontab'=>1]);
- echo "执行成功";
- }else{
- echo '执行失败';
- }
- }
- $redis->set("invoce_tab",0);
- // $this->Jobdo();
- $output->writeln('queue');
- }
- }
|