我使用Rails 5
和DelayedJob
设置后台任务,以便进行简单的电子邮件通知。
查看我的生产日志,并提出以下项目:
[2016-08-05T20:22:15.094172 #10616] DEBUG -- :
Delayed::Backend::ActiveRecord::Job Load (1.0ms) UPDATE "delayed_jobs"
SET locked_at = '2016-08-06 10:22:15.092656', locked_by = 'delayed_job
host:jiably pid:10616' WHERE id IN (SELECT "delayed_jobs"."id" FROM
"delayed_jobs" WHERE ((run_at <= '2016-08-06 10:22:15.091986' AND
(locked_at IS NULL OR locked_at < '2016-08-06 06:22:15.092073') OR
locked_by = 'delayed_job host:vps-server-name pid:10616') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
队列中没有作业,当我测试应用程序的电子邮件通知时,作业似乎处理得很好。
这是正常的吗?它似乎经常重复并添加到日志文件中。我确实有logrotate设置,但不确定它是否是我做过或错过的配置。
感谢您对此有所了解。
答案 0 :(得分:0)
您可能会看到Delayed :: Job issue 477 here。编辑:据我所知,你说这发生在生产中。修复程序或您的配置需要进行修改以匹配该问题。
如果是这样,修复就在那里。我在这里实现了config / initializers / delayed_job_config.rb(注意我已经实现了分段):
Delayed::Worker.max_attempts = 5
Delayed::Worker.delay_jobs = !Rails.env.test?
Delayed::Worker.sleep_delay = 10
Delayed::Worker.default_priority = 100
# Prevent excessive logging every 5 seconds when Logger level < WARN
# https://github.com/collectiveidea/delayed_job/issues/477
if %w(development staging).include? Rails.env
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