What happens to QueueWorker when the TTR is over?

This applies to laravel 5.3, beanstalk, ttr and timeouts working with Queue and QueueWorkers. TTR: https://github.com/kr/beanstalkd/wiki/faq

If I understand correctly that the job in the queue receives the state reserved when QueueWorker selects it. This job state will be returned to the state when ttr ends. But what happens to QueueWorker?

Suppose QueueWorker has a timeout set to 600 with the following command:

php artisan queue:work --tries=1 --timeout=600 --sleep=0 

ttr is set to 60 seconds by default.

During the job, the request is made to another site and it takes 120 seconds to respond. After 60 seconds, the job returns to the ready state as TTR. Will QueueWorker work on the job until a response is received, maximum 600 seconds? Or will QueueWorker stop working on the task when it reaches the TTR?

+5
source share
1 answer

Actually, QueueWorker will work until the task is completed. When a queue worker starts without the demon flag, the following code will be run.

  return $this->worker->pop( $connection, $queue, $delay, $this->option('sleep'), $this->option('tries') ); 

Referance: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Queue/Console/WorkCommand.php#L123

What really happens in this code is a pop task from the queue and run this task as a command.

 public function process($connection, Job $job, $maxTries = 0, $delay = 0) { if ($maxTries > 0 && $job->attempts() > $maxTries) { return $this->logFailedJob($connection, $job); } try { $job->fire(); $this->raiseAfterJobEvent($connection, $job); return ['job' => $job, 'failed' => false]; } catch (Exception $e) { if (! $job->isDeleted()) { $job->release($delay); } throw $e; } catch (Throwable $e) { if (! $job->isDeleted()) { $job->release($delay); } throw $e; } } 

Link: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Queue/Worker.php#L213

Digging the source for more information https://github.com/laravel/framework/tree/5.2/src/Illuminate/Queue

+3
source

Source: https://habr.com/ru/post/1261640/


All Articles