run.py 1.17 KB
Newer Older
1
2
3
# run.py

import os
4
import time
5
import tasks
6
import vars
7

8
9
from flask import session
from flask_socketio import SocketIO, join_room
10
from app import create_app
11
12
13
from gevent import monkey
monkey.patch_all(subprocess=True)

14
15
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
16
app.config['SECRET_KEY'] = vars.key
17
socketio = SocketIO(app, cors_allowed_origins=vars.cors_allowed_origins, message_queue=vars.message_queue)
18

19
@socketio.on('join_room')
20
def on_room(json):
21
    room = str(session['uid'])
22
    referrer = json['referrer']
23
24
    join_room(room)
    print('\t\t\t|-----Room ID: ' + room)
25
    print('\t\t\t|-----Referrer: ' + referrer)
26

27
28
@socketio.on('request account')
def request_account(json, methods=['GET', 'POST']):
Mitchell Moore's avatar
Mitchell Moore committed
29
    print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
30
31
    room = str(session['uid'])
    print("Room: {}".format(room))
32
    try:
33
        tasks.celery_create_account.delay(json, session=room )
34
35
    except Exception as e:
        print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
36
        socketio.emit("Account creation failed", room)
37

38
if __name__ == '__main__':
39
    socketio.run(app, host='0.0.0.0')