Skip to content
Snippets Groups Projects
tasks.py 884 B
Newer Older
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)