Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Created August 12, 2021 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/6be2cd72161fc9bebf3b3f8ec3e3f226 to your computer and use it in GitHub Desktop.
Save jrochkind/6be2cd72161fc9bebf3b3f8ec3e3f226 to your computer and use it in GitHub Desktop.
patch Rails resque adapter to be willing to enqueue_at NOW
# monkey patch resque adapter to be willing to enqueue_at NOW,
# to let us use ActiveJob retry_on with wait: 0. Resque
# can't enqueue in the future without resque-scheduler,
# but we can enqueue at wait:0/NOW.
module AllowResqueEnqueueAtNow
def enqueue_at(job, timestamp) #:nodoc:de
if !Resque.respond_to?(:enqueue_at_with_queue) && timestamp.to_i <= Time.now.to_i
# we don't have resque-scheduler, but it's asking for it to run RIGHT NOW anyway,
# just enqueue as usual.
enqueue(job)
else
super
end
end
end
ActiveJob::QueueAdapters::ResqueAdapter.prepend(AllowResqueEnqueueAtNow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment