tasks.py 884 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from celery import Celery
import time
from flask_socketio import SocketIO
import subprocess

from gevent import monkey
monkey.patch_all(subprocess=True)

broker_url = 'amqp://reggie:reggie@ohpc:5672/'
#broker_url = 'amqp://'
celery = Celery('flask_user_reg', broker=broker_url)

# socketio = SocketIO(message_queue='amqp:///socketio')


@celery.task
def celery_create_account(username, fullname, reason, room, socketio):
    # Todo: Ravi's and Louis's code goes here
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
    socketio.emit("creating account", room=room)
    print(username)
    subprocess.call(["/opt/rabbitmq_agents/flask_producer.py", "ohpc_account_create", username])
    time.sleep(5)
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
    socketio.emit('account ready', room=room)