ActiveJob与Resque:使用意外参数排队作业

3

尝试实现某种取消作业功能。为了销毁Resque作业, 需要传递特定的参数。但是似乎我错误地传递了一些不必要的信息。

enter image description here

我希望只有参数值在外部括号内。我是这样创建工作的:

PhysicalServerProvisionJob.perform_later('123')                        

我想能够:

Resque::Job.destroy(:default, PhysicalServerProvisionJob, '123')

然而,由于传递的额外信息,这是不可能的。如果无法避免,是否还有其他方法可以销毁特定的排队作业?
2个回答

1

通过这个答案的帮助,我用以下方法解决了问题:

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

1
因为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

1
如果我在同一队列上有多个相同类别的工作,这样就行不通了。 - Jerrod
@Jerrod 我认为这种方法仍然可行,你只需要在 job.args 上添加其他条件即可。在这个例子中,我只检查了类名的 job.args,但你可以根据哈希表中的任何内容进行过滤。 - Jared

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接