has_interruptible_sleep.rb 432 B

12345678910111213141516
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module BackgroundServices::Concerns::HasInterruptibleSleep
  3. extend ActiveSupport::Concern
  4. # Sleep in short intervals so that we can handle TERM/INT signals timely.
  5. # @param [Integer] seconds to sleep for
  6. def interruptible_sleep(interval)
  7. interval.times do
  8. break if BackgroundServices.shutdown_requested
  9. sleep 1
  10. end
  11. end
  12. end