Class: Maestrano::Connector::Rails::PushToConnecJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/maestrano/connector/rails/push_to_connec_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(organization, entities_hash) ⇒ Object

expected hash: => [entity1, entity2], “external_entity_name2” => []



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/maestrano/connector/rails/push_to_connec_job.rb', line 6

def perform(organization, entities_hash)
  return unless organization.sync_enabled && organization.oauth_uid

  connec_client = Maestrano::Connec::Client[organization.tenant].new(organization.uid)

  entities_hash.each do |external_entity_name, entities|
    if entity_instance_hash = find_entity_instance(external_entity_name)
      entity_instance = entity_instance_hash[:instance]
      next unless organization.synchronized_entities[entity_instance_hash[:name].to_sym]
      if entity_instance_hash[:is_complex]
        mapped_entities = entity_instance.consolidate_and_map_data(Hash[ *entity_instance.class.connec_entities_names.collect{|name| [ name, []]}.flatten(1) ], Hash[ *entity_instance.class.external_entities_names.collect{|name| name == external_entity_name ? [name, entities] : [ name, []]}.flatten(1) ], organization, {})
      else
        mapped_entities = entity_instance.consolidate_and_map_data([], entities, organization, {})
      end

      entity_instance.push_entities_to_connec(connec_client, mapped_entities[:external_entities], organization)
    else
      Rails.logger.warn "Called push to connec job with unknow entity: #{external_entity_name}"
    end
  end
end