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

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

9
10
from flask import session
from flask_socketio import SocketIO, join_room
11
12
13

from app import create_app

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

17
18
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
19
20
app.config['SECRET_KEY'] = vars.key
socketio = SocketIO(app, message_queue= vars.message_queue)
21
22


23
24
@socketio.on('join_room')
def on_room():
Mitchell Moore's avatar
Mitchell Moore committed
25

26
    room = str(session['uid'])
27
28
    join_room(room)
    print('\t\t\t|-----Room ID: ' + room)
29
30


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


43
if __name__ == '__main__':
44
    socketio.run(app, host='0.0.0.0')