LoginSignup
4
3

More than 5 years have passed since last update.

delayed_job の daemon がログを吐くのを抑制

Last updated at Posted at 2013-04-14
development.log
  SQL (0.4ms)  UPDATE `delayed_jobs` SET `locked_at` = '2013-04-14 05:23:00', `locked_by` = 'delayed_job host:hoge.lan pid:74793' WHERE ((run_at <= '2013-04-14 05:23:00' AND (locked_at IS NULL OR locked_at < '2013-04-14 01:23:00') OR locked_by = 'delayed_job host:hoge.lan pid:74793') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
  SQL (0.4ms)  UPDATE `delayed_jobs` SET `locked_at` = '2013-04-14 05:23:05', `locked_by` = 'delayed_job host:hoge.lan pid:74793' WHERE ((run_at <= '2013-04-14 05:23:05' AND (locked_at IS NULL OR locked_at < '2013-04-14 01:23:05') OR locked_by = 'delayed_job host:hoge.lan pid:74793') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

こんな感じのログが毎秒出力されるので、非常に精神衛生上よろしくない。
止めましょう。 Rails4 の方はコメント参照。

initializers/delayed_job.rb
module Delayed
  class Job
    class << self
      def reserve_with_log_silencer(worker, max_run_time = Worker.max_run_time)
        silence { reserve_without_log_silencer(worker, max_run_time) }
      end
      alias_method_chain :reserve, :log_silencer
    end
  end
end
4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3