问题
Trying to implement some kind of cancel job functionality. In order to destroy a job with Resque, one needs the specific arguments passed to it. It appears I'm passing in unintended information by mistake though.
I'm expecting just the arguments value to be within the outside brackets. I'm creating the job like so:
PhysicalServerProvisionJob.perform_later('123')
I'd like to be able to:
Resque::Job.destroy(:default, PhysicalServerProvisionJob, '123')
However this isn't possible due to the extra information passed in. If this is unavoidable, is there another way to destroy a specific queued job?
回答1:
Because Resque::Job.destroy
is looking for an exact match of all arguments, it's not going to be helpful for looking up an ActiveJob class.
Here's the script I wrote to solve this:
# Pop jobs off the queue until there are no more
while job = Resque.reserve('default')
# Check this job for the ActiveJob class name we're looking for;
# if it does not match, push it back onto a different queue
unless job.args.to_s.include?('PhysicalServerProvisionJob')
Resque.push('another_queue', class: job.payload_class.to_s, args: job.args)
end
end
回答2:
With help from this answer here, I solved the problem this way:
Resque.size('default').times do
job = Resque.reserve('default')
next if job.nil? || job.args.first['arguments'].first == id
Resque.push('default', class: job.payload_class.to_s, args: job.args)
end
来源:https://stackoverflow.com/questions/35589052/activejob-with-resque-enqueuing-jobs-with-uninteded-arguments