tasks.py 897 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
18
def send_msg(event, room):
   print("Post '{}' to room '{}'".format(event,room))
   socketio.emit(event, room=room)
19

20

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