How to get all pending jobs in laravel queue on redis?

后端 未结 7 932
抹茶落季
抹茶落季 2020-12-13 10:06

Queue listener was not started on a server, some jobs where pushed (using Redis driver).

How could I count (or get all) theses jobs ? I did not found any artisan co

7条回答
  •  时光说笑
    2020-12-13 10:30

    I have two queues, a default queue and a low_prio queue in my laravel 5.7 project.

    connection($connection)
                ->zrange('queues:' . $queuename . ':delayed', -9999, 9999);
    
            $default_reserved = \Queue::getRedis()
                ->connection($connection)
                ->zrange('queues:' . $queuename . ':reserved', -9999, 9999);
    
            $queuename        = 'low_prio';
            $low_prio_delayed = \Queue::getRedis()
                ->connection($connection)
                ->zrange('queues:' . $queuename . ':delayed', -9999, 9999);
    
            $low_prio_reserved = \Queue::getRedis()
                ->connection($connection)
                ->zrange('queues:' . $queuename . ':reserved', -9999, 9999);
    
            $this->getQueueData('default delayed', $default_delayed);
            $this->getQueueData('default reserved', $default_reserved);
            $this->getQueueData('low prio delayed', $low_prio_delayed);
            $this->getQueueData('low prio reserved', $low_prio_reserved);
    
            $this->info(join("\n", $this->lines));
    
        }
    
        private function getQueueData($title, $arr)
        {
            $this->lines[] = "*** $title ***";
            if (count($arr) == 0) {
                $this->lines[] = "Nothing on queue";
                $this->lines[] = "";
                return;
            }
    
            foreach ($arr as $json) {
                $queue = json_decode($json);
                $data  = $queue->data;
    
                if (isset($data) && isset($data->command)) {
                    $this->getCommands($data->command);
                }
            }
            $this->lines[] = "";
    
        }
    
        private function getCommands($serialized)
        {
    
            $readable = str_replace(
                'O:43:"Illuminate\Foundation\Console\QueuedCommand',
                'O:33:"App\Support\ReadableQueuedCommand',
                $serialized);
    
            $readable = unserialize($readable);
            $command  = $readable->getData();
    
            $attribs = [];
            $options = $command[1];
            foreach ($options as $key => $value) {
                $attribs[] = $key . '=' . $value;
            }
    
            $this->lines[] = $command[0] . ' ' . join(" - ", $attribs);
        }
    
    }
    

    The ReadableQueuedCommand looks like this

    data;
        }
    }
    

    The artisan command then lists all in queue

    > php artisan jobs:on:queue
    
    *** default delayed ***
    Nothing on queue
    
    *** default reserved ***
    Nothing on queue
    
    *** low prio delayed ***
    Nothing on queue
    
    *** low prio reserved ***
    oppty:time:profile --by-dataset=2
    oppty:on:reset:pages --by-dataset=2
    
    

提交回复
热议问题