Newer
Older

Krish Moodbidri
committed
import time
from celery import Celery
from flask_socketio import SocketIO

Krish Moodbidri
committed
import rc_util
Mitchell Moore
committed
broker_url = vars.broker_url
Mitchell Moore
committed
celery = Celery('flask_user_reg', broker=broker_url)
socketio = SocketIO(message_queue=vars.message_queue)
Mitchell Moore
committed
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()
Mitchell Moore
committed
Ravi Tripathi
committed
def send_msg(event, room):
print("Post '{}' to room '{}'".format(event,room))
socketio.emit(event, room=room)
Mitchell Moore
committed
Mitchell Moore
committed
Mitchell Moore
committed
@celery.task
def celery_create_account(json, session):
Ravi Tripathi
committed
room = session
username= json['username']
email= json['email']
fullname= json['fullname']
reason= json['reason']
Mitchell Moore
committed
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
Ravi Tripathi
committed
send_msg('creating account', room)
Mitchell Moore
committed
print(username)

Krish Moodbidri
committed
rc_util.add_account(username, email, fullname, reason)
rc_util.consume(username, routing_key=f'complete.{username}', callback=callback)
send_msg('account ready', room)