Class: Etna::Clients::Magma::RecordSynchronizationWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::RecordSynchronizationWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/record_synchronization_workflow.rb
Instance Attribute Summary collapse
-
#ignore_update_errors ⇒ Object
Returns the value of attribute ignore_update_errors.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#source_client ⇒ Object
Returns the value of attribute source_client.
-
#target_client ⇒ Object
Returns the value of attribute target_client.
Instance Method Summary collapse
- #copy_all_models ⇒ Object
-
#copy_model(model_name, copied_models = Set.new) ⇒ Object
TODO: Add paging here to support large payloads.
- #crud ⇒ Object
- #source_models ⇒ Object
- #target_models ⇒ Object
Instance Attribute Details
#ignore_update_errors ⇒ Object
Returns the value of attribute ignore_update_errors
6 7 8 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 6 def ignore_update_errors @ignore_update_errors end |
#project_name ⇒ Object
Returns the value of attribute project_name
6 7 8 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 6 def project_name @project_name end |
#source_client ⇒ Object
Returns the value of attribute source_client
6 7 8 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 6 def source_client @source_client end |
#target_client ⇒ Object
Returns the value of attribute target_client
6 7 8 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 6 def target_client @target_client end |
Instance Method Details
#copy_all_models ⇒ Object
54 55 56 57 58 59 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 54 def copy_all_models copied_models = Set.new target_models.model_keys.each do |model_name| copy_model(model_name, copied_models) end end |
#copy_model(model_name, copied_models = Set.new) ⇒ Object
TODO: Add paging here to support large payloads
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 24 def copy_model(model_name, copied_models = Set.new) if copied_models.include?(model_name) return end copied_models.add(model_name) descendants = source_models.to_directed_graph.descendants("project") (descendants[model_name] || []).each do |required_model| copy_model(required_model, copied_models) do |update| yield update if block_given? end end crud.page_records(model_name) do |documents| yield [model_name, documents] if block_given? begin crud.update_records do |update_request| documents.document_keys.each do |identifier| record = documents.document(identifier) record = record.each.select { |k, v| v != nil && !v.is_a?(Array) }.to_h update_request.update_revision(model_name, identifier, record) end end rescue => e raise unless ignore_update_errors end end end |
#crud ⇒ Object
13 14 15 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 13 def crud @crud ||= MagmaCrudWorkflow.new(project_name: project_name, magma_client: target_client) end |
#source_models ⇒ Object
17 18 19 20 21 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 17 def source_models @source_models ||= source_client.retrieve( RetrievalRequest.new( project_name: project_name, model_name: 'all')).models end |
#target_models ⇒ Object
7 8 9 10 11 |
# File 'lib/etna/clients/magma/workflows/record_synchronization_workflow.rb', line 7 def target_models @target_models ||= begin target_client.retrieve(RetrievalRequest.new(project_name: self.project_name, model_name: 'all')).models end end |