Newer
Older
# run.py
import os
Mitchell Moore
committed
import time
Mitchell Moore
committed
import tasks
Mitchell Moore
committed
Mitchell Moore
committed
from flask import session
from flask_socketio import SocketIO, join_room
from app import create_app
Ravi Tripathi
committed
from gevent import monkey
monkey.patch_all(subprocess=True)
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
app.config['SECRET_KEY'] = vars.key
socketio = SocketIO(app, cors_allowed_origins=vars.cors_allowed_origins, message_queue=vars.message_queue)
Mitchell Moore
committed
Ravi Tripathi
committed
@socketio.on('join_room')
Mitchell Moore
committed
def on_room(json):
Mitchell Moore
committed
room = str(session['uid'])
Mitchell Moore
committed
referrer = json['referrer']
Mitchell Moore
committed
join_room(room)
print('\t\t\t|-----Room ID: ' + room)
Mitchell Moore
committed
print('\t\t\t|-----Referrer: ' + referrer)
Mitchell Moore
committed
Mitchell Moore
committed
@socketio.on('request account')
def request_account(json, methods=['GET', 'POST']):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
room = str(session['uid'])
print("Room: {}".format(room))
Mitchell Moore
committed
try:
tasks.celery_create_account.delay(json, session=room )
Mitchell Moore
committed
except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
Mitchell Moore
committed
socketio.emit("Account creation failed", room)
Mitchell Moore
committed
@socketio.on('request certification')
def certify_account(json, methods=['GET', 'POST']):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
room = str(session['uid'])
print("CERTIFY Room: {}".format(room))
try:
tasks.celery_certify_account(json, session=room )
except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account certification: ", e)
socketio.emit("Account certification failed", room)
if __name__ == '__main__':
Mitchell Moore
committed
socketio.run(app, host='0.0.0.0')