我可以确定Ruby代码是否在Sidekiq作业中执行?

时间:2018-01-10 15:25:24

标签: ruby sidekiq

我可以执行以下操作吗?如果是,我该如何实施in_sidekiq_job

def method_for_anyone_to_call
  if in_sidekiq_job
    puts "hey! I'm running in a Sidekiq job."
  end
end

1 个答案:

答案 0 :(得分:2)

您可以使用Sidekiq.server?,即:

def method_for_anyone_to_call
  if Sidekiq.server?
    puts "hey! I'm running in a Sidekiq job."
  end
end