delayed_job.rb 926 B

123456789101112131415161718192021
  1. Delayed::Worker.destroy_failed_jobs = false
  2. Delayed::Worker.max_attempts = 5
  3. Delayed::Worker.max_run_time = (ENV['DELAYED_JOB_MAX_RUNTIME'].presence || 2).to_i.minutes
  4. Delayed::Worker.read_ahead = 5
  5. Delayed::Worker.default_priority = 10
  6. Delayed::Worker.delay_jobs = !Rails.env.test?
  7. Delayed::Worker.sleep_delay = (ENV['DELAYED_JOB_SLEEP_DELAY'].presence || 10).to_f
  8. Delayed::Worker.logger = Rails.logger
  9. # Delayed::Worker.logger = Logger.new(Rails.root.join('log', 'delayed_job.log'))
  10. # Delayed::Worker.logger.level = Logger::DEBUG
  11. class Delayed::Job
  12. scope :pending, -> { where("locked_at IS NULL AND attempts = 0") }
  13. scope :awaiting_retry, -> { where("failed_at IS NULL AND attempts > 0 AND locked_at IS NULL") }
  14. scope :failed_jobs, -> { where("failed_at IS NOT NULL") }
  15. end
  16. Delayed::Backend::ActiveRecord.configure do |config|
  17. config.reserve_sql_strategy = :default_sql
  18. end if ENV["DATABASE_ADAPTER"] == "mysql2"