2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2021-05-25 12:30:12 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Freshdesk
|
|
|
|
module SubSequence
|
|
|
|
class Generic < Sequencer::Unit::Base
|
|
|
|
|
|
|
|
uses :dry_run, :import_job, :field_map, :id_map
|
|
|
|
|
2021-08-12 12:04:45 +00:00
|
|
|
attr_accessor :iteration, :result
|
|
|
|
|
|
|
|
EXPECTING = %i[action response].freeze
|
2021-05-25 12:30:12 +00:00
|
|
|
|
|
|
|
def process
|
|
|
|
loop.each_with_index do |_, iteration|
|
|
|
|
@iteration = iteration
|
2021-08-12 12:04:45 +00:00
|
|
|
@result = ::Sequencer.process(sequence_name,
|
|
|
|
parameters: {
|
|
|
|
request_params: request_params,
|
|
|
|
import_job: import_job,
|
|
|
|
dry_run: dry_run,
|
|
|
|
object: object,
|
|
|
|
field_map: field_map,
|
|
|
|
id_map: id_map,
|
|
|
|
skipped_resource_id: skipped_resource_id,
|
|
|
|
},
|
|
|
|
expecting: self.class.const_get(:EXPECTING))
|
|
|
|
break if iteration_should_stop?
|
2021-05-25 12:30:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def request_params
|
|
|
|
{
|
2021-07-28 14:40:08 +00:00
|
|
|
page: page,
|
2021-05-25 12:30:12 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-28 14:40:08 +00:00
|
|
|
def page
|
|
|
|
iteration + 1
|
|
|
|
end
|
|
|
|
|
2021-05-25 12:30:12 +00:00
|
|
|
def object
|
2021-07-28 14:40:08 +00:00
|
|
|
@object ||= self.class.name.demodulize.singularize
|
2021-05-25 12:30:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sequence_name
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2021-07-28 14:40:08 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-08-12 12:04:45 +00:00
|
|
|
def skipped_resource_id
|
|
|
|
@skipped_resource_id ||= nil
|
2021-07-28 14:40:08 +00:00
|
|
|
end
|
|
|
|
|
2021-08-12 12:04:45 +00:00
|
|
|
def iteration_should_stop?
|
|
|
|
return true if result[:action] == :failed
|
|
|
|
return true if result[:response].header['link'].blank?
|
2021-07-28 14:40:08 +00:00
|
|
|
|
2021-08-12 12:04:45 +00:00
|
|
|
false
|
2021-07-28 14:40:08 +00:00
|
|
|
end
|
2021-05-25 12:30:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|