ruby-on-rails – 如何忽略Rails中的延迟作业查询记录

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何忽略Rails中的延迟作业查询记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何从log / development.log中沉默/忽略这些延迟作业查询日志?
Delayed::Backend::ActiveRecord::Job Load (1.0ms)  UPDATE "delayed_jobs" SET locked_at = '2013-11-19 19:55:45.053991',locked_by = 'host:desktop-virtual pid:22277' WHERE id IN (SELECT id FROM "delayed_jobs" WHERE ((run_at <= '2013-11-19 19:55:45.053435' AND (locked_at IS NULL OR locked_at < '2013-11-19 15:55:45.053519') OR locked_by = 'host:desktop-virtual pid:22277') AND Failed_at IS NULL) ORDER BY priority ASC,run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
Delayed::Backend::ActiveRecord::Job Load (1.4ms)  UPDATE "delayed_jobs" SET locked_at = '2013-11-19 19:55:50.056977',locked_by = 'host:desktop-virtual pid:22277' WHERE id IN (SELECT id FROM "delayed_jobs" WHERE ((run_at <= '2013-11-19 19:55:50.056484' AND (locked_at IS NULL OR locked_at < '2013-11-19 15:55:50.056530') OR locked_by = 'host:desktop-virtual pid:22277') AND Failed_at IS NULL) ORDER BY priority ASC,run_at ASC LIMIT 1 FOR UPDATE) RETURNING *

我已经尝试将其添加到config / initializers / delayed_job.rb中,它会路由除了日志/ development.log中仍然存放的间隔查询日志之外的所有内容.

if Rails.env == "development"
  Delayed::Worker.logger = Logger.new(File.join(Rails.root,"log","delayed_job.log"))
end

谢谢.

解决方法

日志行仍然显示,因为该行由ActiveRecord记录,而不是延迟作业.有关更多信息,请参阅 github bug report.这是一个解决方法

在config / initializers / delayed_job_silencer.rb中:

if Rails.env.development?
  module Delayed
    module Backend
      module ActiveRecord
        class Job
          class << self
            alias_method :reserve_original,:reserve
            def reserve(worker,max_run_time = Worker.max_run_time)
              prevIoUs_level = ::ActiveRecord::Base.logger.level
              ::ActiveRecord::Base.logger.level = Logger::WARN if prevIoUs_level < Logger::WARN
              value = reserve_original(worker,max_run_time)
              ::ActiveRecord::Base.logger.level = prevIoUs_level
              value
            end
          end
        end
      end
    end
  end
end

猜你在找的Ruby相关文章