From 68126bdd2a7fb07f4ffc68bca332aa695a714c2c Mon Sep 17 00:00:00 2001
From: atlurie <atlurie@uab.edu>
Date: Thu, 14 Apr 2022 11:30:47 -0500
Subject: [PATCH] Add task success state to msg dict being returned to callback
 queue.

---
 prod_rmq_agents/new_jobs.py   | 8 +++++---
 prod_rmq_agents/ssh_access.py | 8 +++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/prod_rmq_agents/new_jobs.py b/prod_rmq_agents/new_jobs.py
index 4ef2f29..5f26077 100644
--- a/prod_rmq_agents/new_jobs.py
+++ b/prod_rmq_agents/new_jobs.py
@@ -21,7 +21,8 @@ def new_jobs(ch, method, properties, body):
     msg = json.loads(body)
     username = msg["username"]
     action = msg["action"]
-    msg["success"] = False
+    msg["success"] = {}
+    msg["success"][task] = False
 
     corr_id = properties.correlation_id
     reply_to = properties.reply_to
@@ -35,10 +36,11 @@ def new_jobs(ch, method, properties, body):
         elif action == 'unlock':
             unblock_new_jobs = popen(unblock_new_jobs_cmd).read().rstrip()
 
-        msg["success"] = True
+        msg["success"][task] = True
+        logger.info(f"Succeeded in blocking {username}'s jobs getting to run state")
 
     except Exception:
-        msg["success"] = False
+        msg["success"][task] = False
         msg["errmsg"] = "Exception raised while setting maxjobs that can enter run state, check the logs for stack trace"
         logger.error("", exc_info=True)
 
diff --git a/prod_rmq_agents/ssh_access.py b/prod_rmq_agents/ssh_access.py
index 044bf57..6d85b43 100644
--- a/prod_rmq_agents/ssh_access.py
+++ b/prod_rmq_agents/ssh_access.py
@@ -21,7 +21,8 @@ def ssh_access(ch, method, properties, body):
     msg = json.loads(body)
     username = msg["username"]
     action = msg["action"]
-    msg["success"] = False
+    msg["success"] = {}
+    msg["success"][task] = False
 
     corr_id = properties.correlation_id
     reply_to = properties.reply_to
@@ -35,10 +36,11 @@ def ssh_access(ch, method, properties, body):
         elif action == 'unlock':
             unblock_ssh = popen(unblock_ssh_cmd).read().rstrip()
 
-        msg["success"] = True
+        msg["success"][task] = True
+        logger.info(f"User {username} is added to nossh group")
 
     except Exception:
-        msg["success"] = False
+        msg["success"][task] = False
         msg["errmsg"] = "Exception raised, while blocking user's ssh access, check the logs for stack trace"
         logger.error("", exc_info=True)
 
-- 
GitLab