kevindierkx's avatar

Moving Job to different queue during Job execution

By default new jobs get the Queueable trait. This trait contains the onQueue() method used to push new Jobs to a specific queue. However in my current setup: BeanstalkD, Supervisor and a plain Laravel installation using this method 'during' Job execution wont move the job.

OK why would I even want to move the job..? I queue a large number of jobs ~60.000, sadly due to external API constraints I can only handle 300 'pending' jobs at a certain time. These can take a while before they are 'completed' and therefore new Jobs need to be delayed. To prevent my 'tubes' from blocking the 'completion' jobs I've added multiple tubes: high, normal and low. New jobs enter 'normal', completion jobs go to 'high' and jobs that would block the queue go to the 'low' tube. The worker(s) also prefer high before normal etc.

Am I correct using onQueue() during execution isn't intended and something like this is the preferred way for 'moving' jobs?

// Job class
$this->dispatch((new Job($this->dataA, $this->dataB))->onQueue('low')->delay(10)); // Add esssentialy the same job to a different queue.
$this->delete(); // Delete current Job from queue.

When this isn't possible I would prefer the release() or delay() method would have a second parameter for specifying the queue for 'release'.

$this->release(60, 'low');
0 likes
0 replies

Please or to participate in this conversation.