Skip to content
Snippets Groups Projects
Commit 557c7666 authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Update update_state with updated_by field

parent 04a11ccd
No related branches found
No related tags found
2 merge requests!147Merge previous default branch feat-cod-rmq into main,!127Add updated_by field to user_state table
......@@ -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}")
......
......@@ -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,
},
}
)
......
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