Class: ActiveGit::Synchronizer
- Inherits:
-
Object
- Object
- ActiveGit::Synchronizer
- Defined in:
- lib/active_git/synchronizer.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.synchronize(*events) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/active_git/synchronizer.rb', line 4 def self.synchronize(*events) batch = self.new Array(events).flatten.each do |event| event.synchronize batch end batch.run end |
Instance Method Details
#bulk_insert(data) ⇒ Object
34 35 36 |
# File 'lib/active_git/synchronizer.rb', line 34 def bulk_insert(data) bulk_inserts[data.class] << data end |
#define_job(&block) ⇒ Object
38 39 40 |
# File 'lib/active_git/synchronizer.rb', line 38 def define_job(&block) jobs << block end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_git/synchronizer.rb', line 14 def run if bulk_inserts.any? define_job do bulk_inserts.each do |model, records| records.each_slice(ActiveGit.configuration.sync_batch_size) do |batch_records| ActiveGit.configuration.logger.debug "[ActiveGit] Inserting #{model.model_name} models" import_result = model.import batch_records, timestamps: false, validate: false raise SynchronizationError.new(import_result.failed_instances) unless import_result.failed_instances.empty? end end end end ::ActiveRecord::Base.transaction do jobs.each(&:call) end ActiveGit.add_all end |