tasks.py 924 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
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/'
celery = Celery('flask_user_reg', broker=broker_url)

12
socketio = SocketIO(message_queue='amqp://reggie:reggie@ohpc:5672/socketio')
13

14
15
16
def send_msg(event, room):
   print("Post '{}' to room '{}'".format(event,room))
   socketio.emit(event, room=room)
17
18

@celery.task
19
20
def celery_create_account(username, fullname, reason, session):
    room = session
21
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
22
    send_msg('creating account', room)
23
24
25
    print(username)
    subprocess.call(["/opt/rabbitmq_agents/flask_producer.py", "ohpc_account_create", username])
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
26
    send_msg('account ready', room)