尝试实现某种取消作业功能。为了destroy a job with Resque ,需要传递给它的特定参数。不过,我似乎错误地传递了意外信息。
我只希望参数值位于外括号内。我正在这样创建工作:
PhysicalServerProvisionJob.perform_later('123')
我希望能够:
Resque::Job.destroy(:default, PhysicalServerProvisionJob, '123')
但是由于传入了额外的信息,这是不可能的。如果这是不可避免的,是否有另一种方法来销毁特定的排队作业?
最佳答案
因为 Resque::Job.destroy
正在寻找所有参数的精确匹配,所以它对查找 ActiveJob 类没有帮助。
这是我为解决这个问题而编写的脚本:
# 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
关于ruby - 带有 Resque : enqueuing jobs with uninteded arguments 的 ActiveJob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35589052/