From cd62860a5d9526d0ca5dd830fe08958ec766afbf Mon Sep 17 00:00:00 2001 From: Krish M <krish94@uab.edu> Date: Mon, 18 Apr 2022 14:35:02 -0500 Subject: [PATCH] Feat certify account 1. Replaced function call rc_util.update_state with rc_util.certify_account 2. Added callback function for certify_account --- tasks.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index 5721e47..2a2c328 100644 --- a/tasks.py +++ b/tasks.py @@ -35,6 +35,25 @@ def gen_f(room): rc_util.rc_rmq.delete_queue() return callback +def certify_gen_f(room): + def callback(channel, method, properties, body): + msg = json.loads(body) + username = msg['username'] + + if msg['success']: + print(f'Account for {username} has been certified.') + send_msg('certified', room) + else: + print(f"There's some issue while certifying account for {username}") + errmsg = msg.get('errmsg', []) + for err in errmsg: + print(err) + socketio.emit('certify error', errmsg, room= room) + + rc_util.rc_rmq.stop_consume() + rc_util.rc_rmq.delete_queue() + return callback + def send_msg(event, room): socketio.emit(event, room=room) @@ -72,7 +91,7 @@ def celery_certify_account(json, session): print("CERTIFY : "+time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue') send_msg('certifying account', room) print(username) - rc_util.update_state(username, 'ok') + rc_util.certify_account(username, queuename, 'ok', 'all') print('sent account info') print('Waiting for certification...') - send_msg('certified', room) + rc_util.consume(queuename, routing_key=f'certified.{queuename}', callback=certify_gen_f(room)) -- GitLab