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

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

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

from app import create_app

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

16
17
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
18
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
19
socketio = SocketIO(app, message_queue='amqp://reggie:reggie@ohpc:5672/socketio')
20
21


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

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


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


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