diff --git a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py index 844324560135caa6f9e1ce73d714dbcea5ca52f5..d0c66a8ab8663016506a185cef3cc12e801100f0 100755 --- a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py +++ b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py @@ -122,34 +122,39 @@ class ResourceAssigner(): mainParset = parameterset(specification_tree['specification']) momId = mainParset.getInt('Observation.momID', -1) - try: - startTime = datetime.strptime(mainParset.getString('Observation.startTime'), '%Y-%m-%d %H:%M:%S') - endTime = datetime.strptime(mainParset.getString('Observation.stopTime'), '%Y-%m-%d %H:%M:%S') - except ValueError: - logger.warning('cannot parse for start/end time from specification for otdb_id=%s. searching for sane defaults...', (otdb_id, )) - maxPredecessorEndTime = self.getMaxPredecessorEndTime(specification_tree) - - if maxPredecessorEndTime: - startTime = maxPredecessorEndTime + timedelta(minutes=1) - endTime = startTime + timedelta(hours=1) - logger.warning('Applying sane defaults (%s, %s) for start/end time from specification for otdb_id=%s based on maxPredecessorEndTime (%s)', - startTime, endTime, otdb_id, maxPredecessorEndTime) - else: - startTime = datetime.utcnow() + timedelta(hours=1) + timedelta(minutes=1) - endTime = startTime + timedelta(hours=1) - logger.warning('Applying sane defaults (%s, %s) for start/end time from specification for otdb_id=%s one hour from now', - startTime, endTime, otdb_id) - - try: - logger.info('uploading auto-generated start/end time (%s, %s) to otdb for otdb_id=%s', startTime, endTime, otdb_id) - self.otdbrpc.taskSetSpecification(otdb_id, { 'LOFAR.ObsSW.Observation.startTime': startTime.strftime('%Y-%m-%d %H:%M:%S'), - 'LOFAR.ObsSW.Observation.stopTime': endTime.strftime('%Y-%m-%d %H:%M:%S')}) - except Exception as e: - logger.error(e) clusterIsCEP4 = self.checkClusterIsCEP4(mainParset) clusterName = 'CEP4' if clusterIsCEP4 else 'CEP2' + if clusterIsCEP4: + try: + startTime = datetime.strptime(mainParset.getString('Observation.startTime'), '%Y-%m-%d %H:%M:%S') + endTime = datetime.strptime(mainParset.getString('Observation.stopTime'), '%Y-%m-%d %H:%M:%S') + except ValueError: + logger.warning('cannot parse for start/end time from specification for otdb_id=%s. searching for sane defaults...', (otdb_id, )) + maxPredecessorEndTime = self.getMaxPredecessorEndTime(specification_tree) + + taskDuration = mainParset.getInt('Observation.Scheduler.taskDuration', -1) + taskDuration = timedelta(seconds=taskDuration) if taskDuration > 0 else timedelta(hours=1) + + if maxPredecessorEndTime: + startTime = maxPredecessorEndTime + timedelta(minutes=1) + endTime = startTime + taskDuration + logger.warning('Applying sane defaults (%s, %s) for start/end time from specification for otdb_id=%s based on maxPredecessorEndTime (%s)', + startTime, endTime, otdb_id, maxPredecessorEndTime) + else: + startTime = datetime.utcnow() + timedelta(hours=1) + timedelta(minutes=1) + endTime = startTime + taskDuration + logger.warning('Applying sane defaults (%s, %s) for start/end time from specification for otdb_id=%s one hour from now', + startTime, endTime, otdb_id) + + try: + logger.info('uploading auto-generated start/end time (%s, %s) to otdb for otdb_id=%s', startTime, endTime, otdb_id) + self.otdbrpc.taskSetSpecification(otdb_id, { 'LOFAR.ObsSW.Observation.startTime': startTime.strftime('%Y-%m-%d %H:%M:%S'), + 'LOFAR.ObsSW.Observation.stopTime': endTime.strftime('%Y-%m-%d %H:%M:%S')}) + except Exception as e: + logger.error(e) + # insert new task and specification in the radb # any existing specification and task with same otdb_id will be deleted automatically logger.info('doAssignment: insertSpecification momId=%s, otdb_id=%s, status=%s, taskType=%s, startTime=%s, endTime=%s cluster=%s' % @@ -274,7 +279,7 @@ class ResourceAssigner(): task['mom_id'], task['otdb_id']) self.radbrpc.insertTaskPredecessor(successor_task['id'], task['id']) - movePipelineAfterItsPredecessors(successor_task, self.radbrpc, datetime.utcnow()) + movePipelineAfterItsPredecessors(successor_task, self.radbrpc) else: logger.warning('could not find predecessor task with otdb_id=%s in radb for task otdb_id=%s', successor_task['otdb_id'], task['otdb_id']) else: