Reputation: 6023
Ive Laravel queue running but on Database connection, here is the config:
'database' => [
'driver' => 'database',
'connection' => 'mysql',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 190,
'block_for' => 0,
]
This is how I run it:
php artisan queue:work --queue=xyz_queue > storage/logs/queue.log
On the redis CLI, this is what is happening every second:
Upvotes: 1
Views: 2449
Reputation: 9596
It is normal and expected behavior. According to the documentation
Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:
php artisan queue:restart
This command will instruct all queue workers to gracefully "die" after they finish processing their current job so that no existing jobs are lost.
queue:restart
does is that setting current timestamp to the value of illuminate:queue:restart
key.php artisan queue:work
) it gets that timestamp value from illuminate:queue:restart
key and after the job is about to be completed it gets the value again from the same key.It is an efficient way(since Redis is super fast for this kind of scenarios) to detect whether the code is changed and should the jobs should be updated for this code change.
The reason it saves the value into the Redis, "most probably" your cache driver is Redis. If you change it to file
then it will be saving in the file instead and making the get request to that file.
Here are the related methods;
protected function stopIfNecessary(WorkerOptions $options, $lastRestart, $job = null)
{
if ($this->shouldQuit) {
$this->stop();
} elseif ($this->memoryExceeded($options->memory)) {
$this->stop(12);
} elseif ($this->queueShouldRestart($lastRestart)) {
$this->stop();
} elseif ($options->stopWhenEmpty && is_null($job)) {
$this->stop();
}
}
protected function queueShouldRestart($lastRestart)
{
return $this->getTimestampOfLastQueueRestart() != $lastRestart;
}
protected function getTimestampOfLastQueueRestart()
{
if ($this->cache) {
return $this->cache->get('illuminate:queue:restart');
}
}
Upvotes: 1