diff --git a/SAS/ResourceAssignment/TaskPrescheduler/prescheduler.py b/SAS/ResourceAssignment/TaskPrescheduler/prescheduler.py index 1c380a2d1267b7b4eb9f0d68b2b79941e62d2064..8c8cbf36beca21cc71a624395880ef7c55a3e784 100644 --- a/SAS/ResourceAssignment/TaskPrescheduler/prescheduler.py +++ b/SAS/ResourceAssignment/TaskPrescheduler/prescheduler.py @@ -142,24 +142,27 @@ class TaskPrescheduler(OTDBBusListener): """ #TODO might work for all tasks in the future try: otdb_id = treeId - mom_ids = self.momquery.getMoMIdsForOTDBIds([otdb_id]) - if mom_ids: - mom_id = mom_ids[0] + #Race condition when asking MoM as the mom-otdb-adapter might not have heard that the + #task is on approved and might still be on approved pending in MoM. + #mom_ids = self.momquery.getMoMIdsForOTDBIds([otdb_id]) + #So we get the parset for all tasks we receive instead of just for the ones with + #a trigger. + parset = self.otdbrpc.taskGetSpecification( otdb_id=otdb_id )['specification'] + specification = resourceIndicatorsFromParset(parset) + if specification["Observation.momID"]: + mom_id = specification["Observation.momID"] + logger.info('Found mom_id %s for otdb_id %s', (mom_id, otdb_id)) else: mom_id = None - if len(mom_ids) > 1: - logger.warning('Found multiple mom_ids %s', mom_ids) if mom_id: response = self.momquery.get_trigger_id(mom_id) if response['status'] == 'OK': logger.info('Found a task mom_id=%s with a trigger_id=%s', mom_id, response['trigger_id']) #TODO, check for stations and other resources, start/endtime, target position, then update specification - parset = self.otdbrpc.taskGetSpecification( otdb_id=otdb_id )['specification'] - specification = resourceIndicatorsFromParset(parset) cobalt_values = calculateCobaltSettings(specification) - logger.info('prescheduling otdb_id=%s because it was generated by trigger_id=%s', otdb_id, response['trigger_id']) + logger.info('prescheduling otdb_id=%s because it was generated by trigger_id=%s', (otdb_id, response['trigger_id'])) otdb_info = {} otdb_info[OUTPUT_PREFIX + "Cobalt.Correlator.nrBlocksPerIntegration"] = cobalt_values["nrBlocks"] otdb_info[OUTPUT_PREFIX + "Cobalt.Correlator.nrIntegrationsPerBlock"] = cobalt_values["nrSubblocks"] @@ -167,9 +170,9 @@ class TaskPrescheduler(OTDBBusListener): otdb_info[OUTPUT_PREFIX + "Cobalt.Correlator.integrationTime"] = cobalt_values["integrationTime"] self.setOTDBinfo(otdb_id, otdb_info, 'prescheduled') else: - logger.info('Did not find a trigger for task mom_id=%s, because %s', mom_id, response['errors']) + logger.info('Did not find a trigger for task mom_id=%s, because %s', (mom_id, response['errors'])) else: - logger.info('Did not find a mom_id for task otdb_id=%s', otdb_id) + logger.info('Did not find a mom_id for task otdb_id=%s', (otdb_id,)) except Exception as e: logger.error(e)