Fixes #3436 - Unable to sync Exchange contracts (if one contact is unable to process).

This commit is contained in:
Martin Edenhofer 2021-03-16 15:04:38 +00:00 committed by Thorsten Eckel
parent 2354b5f53f
commit d9f4b93f48
3 changed files with 55 additions and 19 deletions

View file

@ -23,16 +23,38 @@ class Sequencer
@default_parameter ||= default_params
end
def sequence_resource(resource)
sequence_parameter = default_parameter.dup
sequence_parameter[:resource] = resource
sequence_parameter = yield(sequence_parameter) if block_given?
sequence_parameter[:resource] = sequence_parameter[:resource].to_h.with_indifferent_access
def sequence_resource(resource = nil, &block)
parameters = sanitized_sequence_parameters!(resource, &block)
return if parameters.blank?
::Sequencer.process(sequence_name,
parameters: sequence_parameter)
parameters: parameters)
end
def sanitized_sequence_parameters!(resource, &block)
parameters = sequence_parameters(resource, &block)
if parameters.nil?
logger.debug { "Skipping processing of Sub-Sequence '#{sequence_name}'. `sequence_resource` block returned `nil` in '#{self.class.name}'." }
return
end
if parameters[:resource].blank?
raise '`resource` parameter missing. It is required as an argument to `sequence_resource` or as `:resource` key value of the block result.'
end
parameters.tap do |result|
result[:resource] = result[:resource].to_h.with_indifferent_access
end
end
def sequence_parameters(resource)
# creates a dup/copy of `default_parameter`
parameters = default_parameter.merge(resource: resource)
return parameters if !block_given?
yield(parameters)
end
def sequence_resources(resources, &block)

View file

@ -14,10 +14,17 @@ class Sequencer
ews_folder_ids.collect do |folder_id|
ews_folder.find(folder_id).items.each do |resource|
attributes = ::Import::Exchange::ItemAttributes.extract(resource)
ews_folder.find(folder_id).items.each do |item|
attributes = ::Import::Exchange::ItemAttributes.extract(item)
extractor.extract(attributes)
break if extractor.enough
rescue => e
Rails.logger.error 'Unable to process Exchange folder item'
Rails.logger.debug { item.inspect }
Rails.logger.error e
nil
end
rescue NoMethodError => e
raise if e.message.exclude?('Viewpoint::EWS::')

View file

@ -41,19 +41,26 @@ class Sequencer
logger.debug { "Fetching and processing #{per_page} items (page: #{page}, offset: #{offset}) from Exchange folder '#{display_path}' (total: #{total})" }
folder.items(opts).each do |item|
process_folders(folder, display_path, opts)
end
end
sequence_resource(item) do |parameters|
def process_folders(folder, display_path, opts)
folder.items(opts).each do |item|
item = parameters[:resource]
sequence_resource do |parameters|
logger.debug { "Extracting attributes from Exchange item: #{item.get_all_properties!.inspect}" }
logger.debug { "Extracting attributes from Exchange item: #{item.get_all_properties!.inspect}" }
parameters.merge(
resource: ::Import::Exchange::ItemAttributes.extract(item),
ews_folder_name: display_path,
)
end
parameters.merge(
resource: ::Import::Exchange::ItemAttributes.extract(item),
ews_folder_name: display_path,
)
rescue => e
Rails.logger.error 'Unable to process Exchange folder item'
Rails.logger.debug { item.inspect }
Rails.logger.error e
nil
end
end
end