tasks.py 895 Bytes
Newer Older
1
2
3
4
from celery import Celery
import time
from flask_socketio import SocketIO
import subprocess
5
import vars
6
7
8
9

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

10
broker_url = vars.broker_url
11
12
celery = Celery('flask_user_reg', broker=broker_url)

13
socketio = SocketIO(message_queue=vars.message_queue)
14

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

@celery.task
20
21
def celery_create_account(username, fullname, reason, session):
    room = session
22
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
23
    send_msg('creating account', room)
24
25
26
    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)
27
    send_msg('account ready', room)