Skip to content
Snippets Groups Projects
Commit b4a763c8 authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-763: allow setting an error reason through REST client

parent 2142b214
No related branches found
No related tags found
1 merge request!637Resolve TMSS-763
......@@ -99,12 +99,13 @@ def main_set_subtask_state():
parser = argparse.ArgumentParser()
parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to set the status on")
parser.add_argument("state", help="The state to set")
parser.add_argument('-e', '--error_reason', default=None, help="Optional error message string when setting a subtask to error.")
parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient')
args = parser.parse_args()
try:
with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session:
changed_subtask = session.set_subtask_status(args.subtask_id, args.state)
changed_subtask = session.set_subtask_status(args.subtask_id, args.state, args.error_reason)
print("%s now has state %s, see: %s" % (changed_subtask['id'], changed_subtask['state_value'], changed_subtask['url']))
except Exception as e:
print(e)
......
......@@ -151,11 +151,14 @@ class TMSSsession(object):
except:
pass
def set_subtask_status(self, subtask_id: int, status: str) -> {}:
def set_subtask_status(self, subtask_id: int, status: str, error_reason=None) -> {}:
'''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.api_url, status)}
if status == 'finishing' or status == 'cancelling':
json_doc['scheduled_on_sky_stop_time'] = datetime.utcnow().isoformat()
if status == 'error':
hostname = socket.gethostname()
json_doc['error_reason'] = error_reason if error_reason is not None else f"set to error via REST client on host '{hostname}'"
logger.info("updating subtask id=%s status to '%s'", subtask_id, status)
response = self.session.patch(url='%s/subtask/%s/' % (self.api_url, subtask_id),
json=json_doc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment