diff options
| author | Xinhui | 2016-09-09 12:48:27 +0200 |
|---|---|---|
| committer | Xinhui | 2016-09-09 12:48:49 +0200 |
| commit | c78802969f4d45028d3854198e311530813ae73b (patch) | |
| tree | 720f119123b051fc609a534c54482c924c65760e /lib/stif | |
| parent | a40c2468c762f039061e71f2e2ba03358e5183ec (diff) | |
| download | chouette-core-c78802969f4d45028d3854198e311530813ae73b.tar.bz2 | |
Model StopAreaReferentialSync
Refs #1609
Diffstat (limited to 'lib/stif')
| -rw-r--r-- | lib/stif/codif_line_synchronization.rb | 6 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 59 |
2 files changed, 36 insertions, 29 deletions
diff --git a/lib/stif/codif_line_synchronization.rb b/lib/stif/codif_line_synchronization.rb index 01ad29afc..9da0e30cc 100644 --- a/lib/stif/codif_line_synchronization.rb +++ b/lib/stif/codif_line_synchronization.rb @@ -61,12 +61,12 @@ module Stif total_deleted = deleted_op + deleted_li + deleted_ne + deleted_gr total_time = elapsed_time_since start_time - LineReferential.first.line_referential_sync.record_status :ok, I18n.t('synchronization.message.success', time: total_time, imported: total_codifligne_elements, deleted: total_deleted) + LineReferential.first.line_referential_sync.record_status :ok, I18n.t('synchronization.codifligne.message.success', time: total_time, imported: total_codifligne_elements, deleted: total_deleted) rescue Exception => e total_time = elapsed_time_since start_time Rails.logger.error "Codifligne:sync - Error: #{e}, ended after #{total_time} seconds" - LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.message.failure', time: total_time) + LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.codifligne.message.failure', time: total_time) end end @@ -174,4 +174,4 @@ module Stif end end end -end
\ No newline at end of file +end diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 55fe3d404..eab86caf1 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -11,45 +11,52 @@ module Stif end def synchronize - start = Time.now - client = Reflex::API.new - processed = [] + tstart = Time.now + begin + client = Reflex::API.new + processed = [] - ['getOR', 'getOP'].each do |method| - results = client.process method - Rails.logger.info "Reflex:sync - Process #{method} done in #{Time.now - start} seconds" - results.each do |type, entries| - Rails.logger.info "Reflex:sync - #{entries.count} #{type} retrieved" - end + ['getOR', 'getOP'].each do |method| + start = Time.now + results = client.process method + Rails.logger.info "Reflex:sync - Process #{method} done in #{Time.now - start} seconds" + results.each do |type, entries| + Rails.logger.info "Reflex:sync - #{entries.count} #{type} retrieved" + end - # Create or update stop_area for every quay, stop_place - stop_areas = results[:Quay].merge(results[:StopPlace]) - start = Time.now - stop_areas.each do |id, entry| - processed << self.create_or_update_stop_area(entry).objectid - end - Rails.logger.info "Reflex:sync - Create or update StopArea done in #{Time.now - start} seconds" + # Create or update stop_area for every quay, stop_place + stop_areas = results[:Quay].merge(results[:StopPlace]) + start = Time.now + stop_areas.each do |id, entry| + processed << self.create_or_update_stop_area(entry).objectid + end + Rails.logger.info "Reflex:sync - Create or update StopArea done in #{Time.now - start} seconds" - # Walk through every entry and set parent stop_area - start = Time.now - stop_areas.each do |id, entry| - self.stop_area_set_parent entry + # Walk through every entry and set parent stop_area + start = Time.now + stop_areas.each do |id, entry| + self.stop_area_set_parent entry + end + Rails.logger.info "Reflex:sync - StopArea set parent done in #{Time.now - start} seconds" end - Rails.logger.info "Reflex:sync - StopArea set parent done in #{Time.now - start} seconds" + + # Purge deleted stop_area + deleted = self.set_deleted_stop_area processed.uniq + self.defaut_referential.stop_area_referential_sync.record_status :ok, I18n.t('synchronization.reflex.message.success', time: Time.now - tstart, imported: processed.uniq.size, deleted: deleted.size) + rescue Exception => e + Rails.logger.error "Reflex:sync - Error: #{e}, ended after #{Time.now - tstart} seconds" + LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.reflex.message.failure', time: Time.now - tstart) end - # Purge deleted stop_area - self.set_deleted_stop_area processed.uniq end def set_deleted_stop_area processed - Rails.logger.info "Reflex:sync - StopArea start deleted_stop_area" start = Time.now deleted = Chouette::StopArea.where(deleted_at: nil).pluck(:objectid).uniq - processed deleted.each_slice(50) do |object_ids| Chouette::StopArea.where(objectid: object_ids).update_all(deleted_at: Time.now) end - Rails.logger.info "Reflex:sync - StopArea #{deleted.size} stop_area deleted since last sync" - Rails.logger.info "Reflex:sync - StopArea purge deleted in #{Time.now - start} seconds" + Rails.logger.info "Reflex:sync - StopArea #{deleted.size} stop_area deleted since last sync in #{Time.now - start} seconds" + deleted end def stop_area_set_parent entry |
