scheduler.rb 794 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Scheduler < ApplicationModel
  3. include ChecksHtmlSanitized
  4. include HasTimeplan
  5. validates :note, length: { maximum: 250 }
  6. sanitized_html :note
  7. scope :failed_jobs, -> { where(status: 'error', active: false) }
  8. # Jobs running more often than every 5 minutes are kept in a continuous thread.
  9. #
  10. # @example
  11. # Scheduler.runs_as_persistent_loop?
  12. #
  13. # return [true]
  14. def runs_as_persistent_loop?
  15. active && period && period <= 5.minutes
  16. end
  17. # This function restarts failed jobs to retry them
  18. #
  19. # @example
  20. # Scheduler.restart_failed_jobs
  21. #
  22. # return [true]
  23. def self.restart_failed_jobs
  24. failed_jobs.each do |job|
  25. job.update!(active: true)
  26. end
  27. true
  28. end
  29. end