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

from app import create_app

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

nick's avatar
nick committed
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('connect')
def socket_connect():
    pass
25

26
27
@socketio.on('join_room')
def on_room():
28

29
30
31
    room = str(session['uid'])
    join_room(room)
    print('\t\t\t|-----Room ID: ' + room)
32
33


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


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