Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set dynamic resque queue

I wish I could decide on which queue to go to work. This is because if the job is scheduled by the server (cronjob) it must be run on a slow queue, if instead it is run by the user it will go on a fast queue. How can I run this in Resque?

Controller

MyJob.perform_later(id, :fast)

Rake task

MyJob.perform_later(id, :slow)

Job

class MyJob < ApplicationJob
  queue_as :default #<-- This has to be dynamic

  def perform(item_id, queue_name)
     ....
  end
like image 754
sparkle Avatar asked Jan 25 '23 21:01

sparkle


1 Answers

I see you are using ActiveJob, you can set the queue by using set method:

Controller

MyJob.set(queue: :fast).perform_later(id)

Rake task

MyJob.set(queue: :slow).perform_later(id)

set method allows you to set more thing than just queue, you can also set eg priority or when should job be performed. See the documentation https://api.rubyonrails.org/v5.2.3/classes/ActiveJob/Core/ClassMethods.html#method-i-set

Note: I presume, you already have slow and fast Resque queues in place and running and only want to use them

like image 80
edariedl Avatar answered Jan 29 '23 14:01

edariedl