tasks.py 993 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
def celery_create_account(json, session):
23
    room = session
24
25
26
27
28
    username= json['username'] 
    email= json['email']
    fullname= json['fullname']
    reason= json['reason']

29
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
30
    send_msg('creating account', room)
31
    print(username)
32
    subprocess.call(["/opt/rabbitmq_agents/create_account.py", username, email, fullname, reason])
33
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
34
    send_msg('account ready', room)