diff --git a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc index a2462a0717583c1669d07e6ead0ab81c00c3c330..5a9bc3f4bea1cadc352584deeb3ff09fba52e036 100644 --- a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc +++ b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc @@ -127,9 +127,17 @@ std::string TMSSBridge::getParsetAsText(int subtask_id) bool TMSSBridge::setSubtaskState(int subtask_id, const string& state) { string queryStr = "/api/subtask/" + to_string(subtask_id) + "/"; + string json_doc = "{ \"state\": \"/api/subtask_state/" + state +"/\""; + if(state == "finishing") { + // set stop_time to 'now' upon finished to get an actual record of when the observation stopped + ptime now = from_time_t(time(0)); + json_doc += ", \"stop_time\": \"" + to_iso_extended_string(now) + "\""; + } + json_doc += " }"; + string result; - if(httpQuery(queryStr, result, "PATCH", "{ \"state\": \"/api/subtask_state/" + state +"/\" }")) { - LOG_INFO_STR("Updated subtask id=" << subtask_id << " to status=" << state); + if(httpQuery(queryStr, result, "PATCH", json_doc)) { + LOG_INFO_STR("Updated subtask state id=" << subtask_id << " with patch: " << json_doc); return true; } diff --git a/SAS/TMSS/client/lib/tmss_http_rest_client.py b/SAS/TMSS/client/lib/tmss_http_rest_client.py index e533b72380b62110293611f3eb360638b4d45ea8..6d8a1f647edac91a3b3974a5551788ec98de9850 100644 --- a/SAS/TMSS/client/lib/tmss_http_rest_client.py +++ b/SAS/TMSS/client/lib/tmss_http_rest_client.py @@ -94,8 +94,12 @@ class TMSSsession(object): def set_subtask_status(self, subtask_id: int, status: str) -> {}: '''set the status for the given subtask, and return the subtask with its new state, or raise on error''' + json_doc = {'state': "%s/subtask_state/%s/" % (self.base_url, status)} + if status == 'finishing': + json_doc['stop_time'] = datetime.utcnow().isoformat() + response = self.session.patch(url='%s/subtask/%s/' % (self.base_url, subtask_id), - json={'state': "%s/subtask_state/%s/" % (self.base_url, status)}, + json=json_doc, params={'format':'json'}) if response.status_code >= 200 and response.status_code < 300: diff --git a/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py index 76886db52fd294699ada00094d7269e222916002..e23874fc0c9b9b3bf4ed0a0f252ad3ce71c552d7 100644 --- a/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py +++ b/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py @@ -247,16 +247,10 @@ class Subtask(BasicCommon): if duplicate_names: raise ValidationError("Pointings defined in the same Subtask must have unique names. Duplicate names %s in subtask id=%s." % (duplicate_names, self.pk)) - # check if we have a start time or there were predecessors + # check if we have a start time when scheduling if self.state.value == SubtaskState.Choices.SCHEDULED.value and self.__original_state_id == SubtaskState.Choices.SCHEDULING.value: if self.start_time is None: - if self.predecessors.all().count() == 0: raise SubtaskSchedulingException("Cannot schedule subtask id=%s when start time is 'None'." % (self.pk, )) - else: - self.start_time = datetime.utcnow() - - if self.state.value == SubtaskState.Choices.FINISHING.value: - self.stop_time = datetime.utcnow() super().save(force_insert, force_update, using, update_fields)