Commit 431f54d5 authored by Krish Moodbidri's avatar Krish Moodbidri
Browse files

Added factory function/wrapper function around callback to be able to send message via room

Changed account error message from send_msg to use socket.emit and send the error message to the UI
Removed account timeout while testing, to ensure error's caused are only due to rabbitmq account create error and not timeout from client to server
parent a7358eec
...@@ -16,23 +16,26 @@ celery = Celery('flask_user_reg', broker=broker_url) ...@@ -16,23 +16,26 @@ celery = Celery('flask_user_reg', broker=broker_url)
socketio = SocketIO(message_queue=vars.message_queue) socketio = SocketIO(message_queue=vars.message_queue)
timeout = 60 timeout = 60
def callback(channel, method, properties, body): def gen_f(room):
def callback(channel, method, properties, body):
msg = json.loads(body) msg = json.loads(body)
username = msg['username'] username = msg['username']
if msg['success']: if msg['success']:
print(f'Account for {username} has been created.') print(f'Account for {username} has been created.')
send_msg('account ready', room)
else: else:
print(f"There's some issue while creating account for {username}") print(f"There's some issue while creating account for {username}")
errmsg = msg.get('errmsg', []) errmsg = msg.get('errmsg', [])
for err in errmsg: for err in errmsg:
print(err) print(err)
socketio.emit('account error', errmsg, room= room)
rc_util.rc_rmq.stop_consume() rc_util.rc_rmq.stop_consume()
rc_util.rc_rmq.delete_queue() rc_util.rc_rmq.delete_queue()
return callback
def send_msg(event, room): def send_msg(event, room):
print("Post '{}' to room '{}'".format(event,room))
socketio.emit(event, room=room) socketio.emit(event, room=room)
def timeout_handler(signum, frame): def timeout_handler(signum, frame):
...@@ -53,11 +56,8 @@ def celery_create_account(json, session): ...@@ -53,11 +56,8 @@ def celery_create_account(json, session):
rc_util.add_account(username, email, fullname, reason) rc_util.add_account(username, email, fullname, reason)
print('sent account info') print('sent account info')
# Set initial timeout timer
signal.signal(signal.SIGALRM, timeout_handler)
signal.setitimer(signal.ITIMER_REAL, timeout)
print('Waiting for completion...') print('Waiting for completion...')
rc_util.consume(username, routing_key=f'complete.{username}', callback=callback) #print(callback(self.EXCHANGE, self.EXCHANGE,self.EXCHANGE,self.EXCHANGE))
send_msg('account ready', room) rc_util.consume(username, routing_key=f'complete.{username}', callback=gen_f(room))
#send_msg('account ready', room)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment