app/jobs/maestrano/connector/rails/concerns/synchronization_job.rb in maestrano-connector-rails-2.3.2 vs app/jobs/maestrano/connector/rails/concerns/synchronization_job.rb in maestrano-connector-rails-2.3.3
- old
+ new
@@ -12,25 +12,25 @@
def find_job(organization_id)
queue = Sidekiq::Queue.new(:default)
queue.find do |job|
job_organization_id = begin
- job.item['args'][0]['arguments'].first
- rescue
- false
- end
+ job.item['args'][0]['arguments'].first
+ rescue
+ false
+ end
organization_id == job_organization_id
end
end
def find_running_job(organization_id)
Sidekiq::Workers.new.find do |_, _, work|
job_organization_id = begin
- work['payload']['args'][0]['arguments'].first
- rescue
- false
- end
+ work['payload']['args'][0]['arguments'].first
+ rescue
+ false
+ end
work['queue'] == 'default' && organization_id == job_organization_id
end
rescue
nil
end
@@ -73,10 +73,11 @@
# We also do batched sync as the first one can be quite huge
if last_synchronization.nil?
Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, 'First synchronization ever. Doing two half syncs to allow smart merging to work its magic.')
organization.synchronized_entities.each do |entity, settings|
next unless settings[:can_push_to_connec] || settings[:can_push_to_external]
+
Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "First synchronization ever. Doing half sync from external for #{entity}.")
first_sync_entity(entity.to_s, organization, connec_client, external_client, last_synchronization_date, opts, true)
Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "First synchronization ever. Doing half sync from Connec! for #{entity}.")
first_sync_entity(entity.to_s, organization, connec_client, external_client, last_synchronization_date, opts, false)
end
@@ -88,10 +89,11 @@
sync_entity(entity, organization, connec_client, external_client, last_synchronization_date, opts)
end
else
organization.synchronized_entities.each do |entity, settings|
next unless settings[:can_push_to_connec] || settings[:can_push_to_external]
+
sync_entity(entity.to_s, organization, connec_client, external_client, last_synchronization_date, opts)
end
end
Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Finished synchronization, organization=#{organization.uid}, status=success")
@@ -134,9 +136,10 @@
# Safety: if the connector does not implement batched calls but has exactly limit entities
# There is a risk of infinite loop
# We're comparing the first record to check that it is different
first_record = Digest::MD5.hexdigest(perform_hash[:first].to_s)
break if last_first_record && first_record == last_first_record
+
last_first_record = first_record
skip += limit
end
end