Created
January 2, 2015 11:51
-
-
Save tbprojects/37cbf289b5431cd9674e to your computer and use it in GitHub Desktop.
Adds an ability to remove delayed jobs from the queue, that were added with ActiveJob.
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
module ActiveJob | |
module Enqueuing | |
module ClassMethods | |
def remove_delayed(*args) | |
job_or_instantiate(*args).remove_delayed | |
end | |
end | |
def remove_delayed | |
self.class.queue_adapter.remove_delayed(self) | |
self | |
end | |
end | |
module QueueAdapters | |
class ResqueAdapter | |
class << self | |
def remove_delayed(job) | |
serialized_job = job.serialize | |
Resque.remove_delayed_selection do |args| | |
if args[0].kind_of?(Hash) && args[0]['job_class'].present? | |
args[0]['job_class'] == serialized_job['job_class'] && | |
args[0]['arguments'] == serialized_job['arguments'] | |
else | |
false | |
end | |
end | |
end | |
end | |
end | |
end | |
module QueueAdapters | |
class TestAdapter | |
def remove_delayed(job) | |
enqueued_jobs.delete_if do |iterated_job| | |
job.class == iterated_job.class && job.arguments == iterated_job.arguments | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment