delayed_job.rb 1.0KB

1234567891011121314151617181920212223242526
  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, -> { where("failed_at IS NOT NULL") }
  15. end
  16. database_deadlocks_when_using_optimized_strategy = lambda do
  17. ENV["DATABASE_ADAPTER"] == "mysql2"
  18. end
  19. Delayed::Backend::ActiveRecord.configure do |config|
  20. config.reserve_sql_strategy = :default_sql
  21. end if database_deadlocks_when_using_optimized_strategy.call