Jerrod Jerrod - 1 month ago 5
Ruby Question

ActiveJob with Resque: enqueuing jobs with uninteded arguments

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.

enter image description here

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?

Answer

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
Comments