generic.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Freshdesk::SubSequence::Generic < Sequencer::Unit::Base
  3. uses :dry_run, :import_job, :field_map, :id_map, :time_entry_available, :skip_initial_contacts
  4. attr_accessor :iteration, :result
  5. EXPECTING = %i[action response].freeze
  6. def process
  7. loop.each_with_index do |_, iteration|
  8. @iteration = iteration
  9. @result = ::Sequencer.process(sequence_name,
  10. parameters: {
  11. request_params: request_params,
  12. import_job: import_job,
  13. dry_run: dry_run,
  14. object: object,
  15. field_map: field_map,
  16. id_map: id_map,
  17. skipped_resource_id: skipped_resource_id,
  18. skip_initial_contacts: skip_initial_contacts,
  19. time_entry_available: time_entry_available,
  20. },
  21. expecting: self.class.const_get(:EXPECTING))
  22. break if iteration_should_stop?
  23. end
  24. end
  25. def request_params
  26. {
  27. page: page,
  28. }
  29. end
  30. def page
  31. iteration + 1
  32. end
  33. def object
  34. @object ||= self.class.name.demodulize.singularize
  35. end
  36. def sequence_name
  37. raise NotImplementedError
  38. end
  39. private
  40. def skipped_resource_id
  41. @skipped_resource_id ||= nil
  42. end
  43. def iteration_should_stop?
  44. return true if result[:action] == :failed || result[:action] == :skipped
  45. return true if result[:response].header['link'].blank?
  46. false
  47. end
  48. end