Skip to content
Snippets Groups Projects
Commit 62f07ca2 authored by Roy de Goei's avatar Roy de Goei
Browse files

TMSS-382 Fix merge with master

parent be390a4d
No related branches found
No related tags found
1 merge request!270Resolve TMSS-382
......@@ -617,10 +617,6 @@ def check_prerequities_for_scheduling(subtask: Subtask) -> bool:
return True
def _assign_or_unassign_resources(subtask: Subtask):
if subtask.state.value not in [SubtaskState.Choices.SCHEDULING.value, SubtaskState.Choices.UNSCHEDULING.value]:
raise SubtaskSchedulingException("Cannot assign resources for subtask id=%d because it is not in (UN)SCHEDULING state. "
"Current state=%s" % (subtask.pk, subtask.state.value))
def _create_ra_specification(_subtask):
# Should we do something with station list, for 'detecting' conflicts it can be empty
......@@ -628,7 +624,7 @@ def _create_ra_specification(_subtask):
return { 'tmss_id': _subtask.id,
'task_type': _subtask.specifications_template.type.value.lower(),
'task_subtype': parset_dict.get("Observation.processSubtype","").lower(),
'status': 'prescheduled',
'status': 'prescheduled' if _subtask.state.value == SubtaskState.Choices.SCHEDULING.value else 'approved',
'starttime': _subtask.start_time,
'endtime': _subtask.stop_time,
'cluster': _subtask.cluster.name,
......@@ -636,7 +632,7 @@ def _create_ra_specification(_subtask):
'specification': parset_dict }
def assign_resources(subtask: Subtask):
def assign_or_unassign_resources(subtask: Subtask):
"""
:param subtask:
"""
......@@ -909,38 +905,6 @@ def get_previous_related_task_blueprint_with_time_offset(task_blueprint):
return previous_related_task_blueprint, time_offset
# todo: maybe this can now be replaced by subtask.relative_start_time
def calculate_start_time(observation_subtask: Subtask):
"""
Calculate the start time of an observation subtask. It should calculate the starttime in case of 'C-T-C train'
The start time of an observation depends on the start_time+duration and offset time of the previous observation
and so its scheduling relations should be known.
If there is no previous observation the 'default' start time is in two minutes from now
For demo purposes, will be changed into dynamic scheduled in the future
Note that the method is not robust now when previous start time is unknown. Also parallel observations are
not supported yet
:param observation_subtask:
:return: start_time (utc time)
"""
previous_related_task_blueprint, time_offset = get_previous_related_task_blueprint_with_time_offset(observation_subtask.task_blueprint)
if previous_related_task_blueprint is None:
# This is the first observation so take start time 2 minutes from now
now = datetime.utcnow()
next_start_time = now + timedelta(minutes=+2, seconds=-now.second, microseconds=-now.microsecond)
else:
# Get the duration of last/previous observation
duration_in_sec = previous_related_task_blueprint.specifications_doc["duration"]
logger.info("Duration of previous observation '%s' (id=%s) is %d seconds",
previous_related_task_blueprint.pk, previous_related_task_blueprint.pk, duration_in_sec)
# Get the previous observation subtask, should actually be one
lst_previous_subtasks_obs = [st for st in previous_related_task_blueprint.subtasks.all() if st.specifications_template.type.value == SubtaskType.Choices.OBSERVATION.value]
previous_subtask_obs = lst_previous_subtasks_obs[0]
logger.info("The previous observation subtask is id=%s", previous_subtask_obs.pk)
if previous_subtask_obs.start_time is None:
raise SubtaskSchedulingException("Cannot compute start_time for subtask id=%s because the its predecessor id=%s has not start_time" %(observation_subtask.id, previous_subtask_obs.id))
next_start_time = previous_subtask_obs.start_time + timedelta(seconds=duration_in_sec+time_offset)
return next_start_time
def schedule_observation_subtask(observation_subtask: Subtask):
''' Schedule the given observation_subtask
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment