tasks.py 980 Bytes
Newer Older
1
2
3
from celery import Celery
import time
from flask_socketio import SocketIO
4
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
celery = Celery('flask_user_reg', broker=broker_url)
12

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
24
25
26
def celery_create_account(user_data):
    username =  user_data.username
    fullname = user_data.fullname
    reason = user_data.reason
    room = user_data.session
27
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
28
29
30
    send_msg('creating account', room)
    print(username)
    subprocess.call(["/opt/rabbitmq_agents/flask_producer.py", "ohpc_account_create", username])
31
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
32
    send_msg('account ready', room)