Created
April 23, 2010 16:08
-
-
Save brettbuddin/376742 to your computer and use it in GitHub Desktop.
I needed to assign priority dynamically (at the time the job is queued up) with Resque.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationJob | |
def self.set_priority(queue, priority) | |
if [:high, :medium, :low].include?(priority) | |
self.instance_eval do | |
@queue = "#{queue}_#{priority}".to_sym | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OurJob.set_priority(:our_queue, :high) | |
Resque.enqueue(OurJob, "Hello world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export QUEUE=our_queue_high,our_queue_medium,our_queue_low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Notice I've left the @queue variable unassigned. | |
class OurJob < ApplicationJob | |
def self.perform(str) | |
puts str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment