background_jobs_helper.rb 962 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. module BackgroundJobsHelper
  3. # clear ActiveSupport::CurrentAttributes caches
  4. # def self.included(base)
  5. # base.teardown do
  6. # ActiveSupport::CurrentAttributes.clear_all
  7. # end
  8. # end
  9. def perform_enqueued_jobs(commit_transaction: false, disable_notification: false)
  10. TransactionDispatcher.commit disable_notification: disable_notification if commit_transaction
  11. original_interface_handle = ApplicationHandleInfo.current
  12. ApplicationHandleInfo.current = 'scheduler'
  13. original_user_id = UserInfo.current_user_id
  14. UserInfo.current_user_id = nil
  15. _success, failure = Delayed::Worker.new.work_off
  16. if failure.nonzero?
  17. raise "#{failure} failed background jobs: #{Delayed::Job.where.not(last_error: nil).inspect}"
  18. end
  19. ensure
  20. UserInfo.current_user_id = original_user_id
  21. ApplicationHandleInfo.current = original_interface_handle
  22. end
  23. end