我正在运行Rails 4.2.8,希望我的任务只在特定条件下运行。目前,我正在调用作业的代码中进行检查,但将逻辑包含在作业类中会更加清晰。有人这样做过吗?
class MyJob < ApplicationJob
before_enqueue do |job|
# check and stop job from being enqueued under certain conditions
end
def perform(args*)
# code here
end
end
我正在使用 Sidekiq 4.2.10 作为后台任务适配器。