【发布时间】:2020-02-07 07:57:13
【问题描述】:
我想在作业完成后自动重新排队。如果没有任何处理,将会有 10 秒的可选延迟。
我可以看到两种方法。第一个是将逻辑放在perform 块中。第二个是使用around_block 功能来做到这一点。
有什么更优雅的方法来做到这一点?
这是一个具有这种逻辑的代码块示例
# Process queue automatically
class ProcessingJob < ApplicationJob
queue_as :processing_queue
around_perform do |_job, block|
if block.call.zero?
# wait for 10 seconds if 0 items was handled
self.class.set(wait: 10.seconds).perform_later
else
# don't rest, there are many work to do
self.class.perform_later
end
end
def perform
# will return number of processed items
ProcessingService.handle_next_batch
end
end
我应该将around_block 逻辑放入perform 函数中吗?
【问题讨论】:
标签: ruby-on-rails ruby sidekiq software-design rails-activejob