From 557c7666d0f8f86f9f56f51ef69aaac129491bc6 Mon Sep 17 00:00:00 2001 From: Bo-Chun Louis Chen <louistw@uab.edu> Date: Mon, 16 May 2022 13:59:14 -0500 Subject: [PATCH] Update update_state with updated_by field --- prod_rmq_agents/user_state.py | 8 +++++++- rc_util.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/prod_rmq_agents/user_state.py b/prod_rmq_agents/user_state.py index 53445c2..f9b74a1 100644 --- a/prod_rmq_agents/user_state.py +++ b/prod_rmq_agents/user_state.py @@ -22,6 +22,7 @@ rc_rmq = RCRMQ({"exchange": rcfg.Exchange, "exchange_type": "topic"}) def user_state(ch, method, properties, body): msg = json.loads(body) username = msg["username"] + updated_by = msg.get("updated_by") op = msg["op"] msg["success"] = False errmsg = "" @@ -47,7 +48,12 @@ def user_state(ch, method, properties, body): state = msg["state"] errmsg = "Updating state of {username} to {state}" table.insert( - {"username": username, "state": state, "date": datetime.now()} + { + "username": username, + "state": state, + "date": datetime.now(), + "updated_by": updated_by, + } ) logger.debug(f"User {username} state updates to {state}") diff --git a/rc_util.py b/rc_util.py index fbb7c39..271debb 100644 --- a/rc_util.py +++ b/rc_util.py @@ -214,7 +214,7 @@ def check_state(username, debug=False): @timeout(rcfg.Function_timeout) -def update_state(username, state, debug=False): +def update_state(username, state, updated_by=None, debug=False): if state not in rcfg.Valid_state: print(f"Invalid state '{state}'") @@ -249,7 +249,12 @@ def update_state(username, state, debug=False): "props": pika.BasicProperties( reply_to=callback_queue, correlation_id=corr_id ), - "msg": {"op": "post", "username": username, "state": state}, + "msg": { + "op": "post", + "username": username, + "state": state, + "updated_by": updated_by, + }, } ) -- GitLab