Created
November 21, 2011 16:32
-
-
Save nevans/1383152 to your computer and use it in GitHub Desktop.
resque: queue.enqueue(job_selector, arg1, arg2)
This file contains hidden or 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
# in response to https://twitter.com/#!/avdi/status/138513455622791168 | |
# Yes, resque's enqueue API is wacky, but in practice it's not a problem, | |
# because it's trivial to route around. | |
# This is untested, and skips any resque enqueue hooks you might have setup. | |
# but those aren't major hurdles to fix. | |
class ResqueQueueWrapper | |
def initialize(queue, resque=Resque) | |
@queue = queue | |
@resque = resque | |
end | |
def enqueue(receiver_constant, *args) | |
unless receiver_constant.respond_to? :queue | |
def receiver_constant.queue; "trick the stupid resque API"; end | |
end | |
@resque::Job.create(@queue, receiver_constant, *args) | |
end | |
end | |
queue = ResqueQueueWrapper.new("queue_name") | |
queue.enqueue(JobName, arg1, arg2) | |
# But I've never done this, because in practice the following is Good Enough: | |
module JobName | |
extend self | |
def queue; :queue_name end | |
def enqueue(*args); Resque.enqueue(self, *args) end | |
def perform(*args) DoStuff.with(*args) end | |
end | |
JobName.enqueue(arg1, arg2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice that JobName.enqueue is 9 parts sugar, 1 part keeping the enqueuing system decoupled from the job requestors.