diff --git a/tasks.py b/tasks.py index 5721e470dbfa34a61b51663f7a7179f61d02c025..2a2c328b8cf97e1fa2343115e05471d6ab4b242e 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))