Class: Maestrano::Connector::Rails::PushToConnecJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Maestrano::Connector::Rails::PushToConnecJob
- Defined in:
- app/jobs/maestrano/connector/rails/push_to_connec_job.rb
Instance Method Summary collapse
-
#perform(organization, entities_hash, opts = {}) ⇒ Object
expected hash: => [entity1, entity2], “external_entity_name2” => [].
Instance Method Details
#perform(organization, entities_hash, opts = {}) ⇒ 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 27 28 29 30 31 32 33 |
# File 'app/jobs/maestrano/connector/rails/push_to_connec_job.rb', line 6 def perform(organization, entities_hash, opts = {}) return unless organization.sync_enabled && organization.oauth_uid connec_client = Maestrano::Connector::Rails::ConnecHelper.get_client(organization) external_client = Maestrano::Connector::Rails::External.get_client(organization) last_synchronization_date = organization.last_synchronization_date entities_hash.each do |external_entity_name, entities| if entity_instance_hash = find_entity_instance(external_entity_name, organization, connec_client, external_client, opts) next unless organization.synchronized_entities[entity_instance_hash[:name].to_sym][:can_push_to_connec] entity_instance = entity_instance_hash[:instance] entity_instance.before_sync(last_synchronization_date) # Build expected input for consolidate_and_map_data mapped_entities = if entity_instance_hash[:is_complex] entity_instance.consolidate_and_map_data(ComplexEntity.build_empty_hash(entity_instance.class.connec_entities_names), ComplexEntity.build_hash_with_entities(entity_instance.class.external_entities_names, external_entity_name, ->(name) { name }, entities)) else entity_instance.consolidate_and_map_data([], entities) end entity_instance.push_entities_to_connec(mapped_entities[:external_entities]) entity_instance.after_sync(last_synchronization_date) else Maestrano::Connector::Rails::ConnectorLogger.log('warn', organization, "Called push to connec job with unknow entity: #{external_entity_name}") end end end |