Skip to content

Instantly share code, notes, and snippets.

@nevans
Created November 21, 2011 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nevans/1383152 to your computer and use it in GitHub Desktop.
Save nevans/1383152 to your computer and use it in GitHub Desktop.
resque: queue.enqueue(job_selector, arg1, arg2)
# 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)
@nevans
Copy link
Author

nevans commented Nov 21, 2011

Notice that JobName.enqueue is 9 parts sugar, 1 part keeping the enqueuing system decoupled from the job requestors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment