check_status.rb 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::System::Import::CheckStatus < Service::Base
  3. attr_reader :source
  4. def initialize
  5. super
  6. @source = Setting.get('import_backend')
  7. running!
  8. end
  9. def execute
  10. # Captain, oh my captain! Again, I'm so sorry, but we need to do it.
  11. return execute_otrs_check if @source == 'otrs'
  12. job_name = "Import::#{@source.camelize}"
  13. job = ImportJob.find_by(name: job_name)
  14. Setting.reload if job.finished_at.present?
  15. job
  16. end
  17. private
  18. def execute_otrs_check
  19. result = Import::OTRS.status_bg
  20. Setting.reload if result[:result] == 'import_done'
  21. result
  22. end
  23. def running!
  24. setup = Service::System::CheckSetup.new
  25. setup.execute
  26. return if setup.status == 'in_progress' && setup.type == 'import'
  27. return if setup.status == 'done' && @source.present?
  28. raise Service::System::Import::Run::ExecuteError, __('No import in progress.')
  29. end
  30. end