delayd_jobを使用するRailsアプリがあります。delay_jobプロセスにあるかどうかを検出したい。何かのようなもの
if in_delayed_job?
# do something only if it is a delayed_job process...
else
# do something only if it is not a delayed_job process...
end
しかし、私はその方法を理解できません。これは私が今使っているものです:
IN_DELAYED_JOB = begin
basename = File.basename $0
arguments = $*
rake_args_regex = /\Ajobs:/
( basename == 'delayed_job' ) ||
( basename == 'rake' && arguments.find{ |v| v =~ rake_args_regex } )
end
@MrDanAが言ったように、別の解決策は次のとおりです。
$ DELAYED_JOB=true script/delayed_job start
# And in the app:
IN_DELAYED_JOB = ENV['DELAYED_JOB'].present?
しかし、それらは私見の弱い解決策です。誰かがより良い解決策を提案できますか?