Archive for April, 2013

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

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

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

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