run.py 1.29 KB
Newer Older
nick's avatar
nick committed
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
nick's avatar
nick committed
10
11
12

from app import create_app

13
14
15
from gevent import monkey
monkey.patch_all(subprocess=True)

nick's avatar
nick committed
16
17
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
18
19
app.config['SECRET_KEY'] = vars.key
socketio = SocketIO(app, message_queue= vars.message_queue)
20

21
22
23
24
25
26
27
28

user_data = {
    'username' : username
    'fullname' : fullname
    'reason' :  reason
    'session' : room
}

29
30
31
@socketio.on('connect')
def socket_connect():
    pass
32

33

34
@socketio.on('join_room')
35
def on_room(json):
36

37
    room = str(session['uid'])
38
    referrer = json['referrer']
39
40
    join_room(room)
    print('\t\t\t|-----Room ID: ' + room)
41
    print('\t\t\t|-----Referrer: ' + referrer)
42
43


44
@socketio.on('request account')
45
def request_account(json, methods=['GET', 'POST']):
46
    print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
Mitchell Moore's avatar
Mitchell Moore committed
47
48
    room = str(session['uid'])
    print("Room: {}".format(room))
49
    try:
50
        tasks.celery_create_account.delay(user_data)
51
52
    except Exception as e:
        print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
53
        socketio.emit("Account creation failed", room)
54
55


nick's avatar
nick committed
56
if __name__ == '__main__':
57
    socketio.run(app, host='0.0.0.0')