delayed_jobs_timeout_per_job.rb 885 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Workaround for ActiveJob not supporting per-job timeouts with delayed_job.
  3. #
  4. # delayed_job does support this (https://github.com/collectiveidea/delayed_job#custom-jobs),
  5. # but since ActiveJob's adapter places a JobWrapper class around the jobs, it fails to work.
  6. #
  7. # Solve this by delegating that method to the actual job class instead.
  8. # Set the maximum possible max_run_time for any job to a high value, and set a sensible default
  9. # in ApplicationJob.max_run_time. Then specific jobs like AsyncImportJob can override this with a
  10. # higher value.
  11. Delayed::Worker.max_run_time = 7.days
  12. module ActiveJob
  13. module QueueAdapters
  14. class DelayedJobAdapter
  15. class JobWrapper
  16. def max_run_time
  17. job_data['job_class'].constantize.max_run_time
  18. end
  19. end
  20. end
  21. end
  22. end