From ff4505b0d539883e8a3223b3c4a053095abf54b5 Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Wed, 10 Mar 2021 01:32:20 -0600
Subject: [PATCH] added callback function with error print to command line

---
 tasks.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/tasks.py b/tasks.py
index 2a1ccc6..d9b1bb3 100644
--- a/tasks.py
+++ b/tasks.py
@@ -4,6 +4,7 @@ from flask_socketio import SocketIO
 import subprocess
 import vars
 import sys
+import json
 
 sys.path.append('/cm/shared/rabbitmq_agents/')
 import rc_util
@@ -16,7 +17,18 @@ celery = Celery('flask_user_reg', broker=broker_url)
 
 socketio = SocketIO(message_queue=vars.message_queue)
 
-def callback():
+def callback(channel, method, properties, body):
+    msg = json.loads(body)
+    username = msg['username']
+
+    if msg['success']:
+        print(f'Account for {username} has been created.')
+    else:
+        print(f"There's some issue while creating account for {username}")
+        errmsg = msg.get('errmsg', [])
+        for err in errmsg:
+            print(err)
+
     rc_util.rc_rmq.stop_consume()
     rc_util.rc_rmq.delete_queue()
 
@@ -39,4 +51,5 @@ def celery_create_account(json, session):
     rc_util.add_account(username, email, fullname, reason)
     print('sent account info')
     print('Waiting for completion...')
-    rc_util.consume(username, routing_key=f'complete.{username}', callback=callback) 
+    rc_util.consume(username, routing_key=f'complete.{username}', callback=callback)
+    send_msg('account ready', room) 
-- 
GitLab