Maintenance::BackfillMboProfileAgentPortSourceTask
Source code
class Maintenance::BackfillMboProfileAgentPortSourceTask < MaintenanceTasks::Task
UNAMBIGUOUS_SLOTS = {
MboProfiles::MidBackOffice::LUMINA => 'RF:UDID:44',
MboProfiles::MidBackOffice::PROTAS => 'RF:UDID:52'
}.freeze
collection_batch_size(1000)
def collection
MboProfile.where(
sync_data_source: MboProfiles::SyncDataSource::AGENT_PORT,
agent_port_source: nil,
mid_back_office: UNAMBIGUOUS_SLOTS.keys
)
end
def process(element)
slot = UNAMBIGUOUS_SLOTS[element.mid_back_office]
return if slot.blank?
return if country_default_mbo?(element)
return if sibling_shares_mid_back_office?(element)
element.update_column(:agent_port_source, slot)
rescue StandardError => e
Rails.logger.error("Failed to backfill agent_port_source for MboProfile #{element.id}: #{e.message}")
end
private
def country_default_mbo?(element)
element.country&.default_mbo_to_country&.default_mbo == element.mid_back_office
end
def sibling_shares_mid_back_office?(element)
MboProfile.joins(:tree_node_to_mbo_profiles)
.where(tree_node_to_mbo_profiles: { tree_node_id: element.company_profiles.select(:id) })
.where(mid_back_office: element.mid_back_office)
.where.not(id: element.id)
.exists?
end
end