tasks.py 1.11 KB
Newer Older
1
2
3
4
from celery import Celery
import time
from flask_socketio import SocketIO
import subprocess
5
import vars
root's avatar
root committed
6
7
8
import sys

sys.path.append('/cm/shared/rabbitmq_agents/')
9
import rc_util
10
11
12
13

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

14
broker_url = vars.broker_url
15
16
celery = Celery('flask_user_reg', broker=broker_url)

17
socketio = SocketIO(message_queue=vars.message_queue)
18

Krish Moodbidri's avatar
Krish Moodbidri committed
19
20
21
def callback():
    rc_util.rc_rmq.stop_consume()
    rc_util.rc_rmq.delete_queue()
22

23
24
25
def send_msg(event, room):
   print("Post '{}' to room '{}'".format(event,room))
   socketio.emit(event, room=room)
26

27

28
@celery.task
29
def celery_create_account(json, session):
30
    room = session
31
32
33
34
35
    username= json['username'] 
    email= json['email']
    fullname= json['fullname']
    reason= json['reason']

36
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
37
    send_msg('creating account', room)
38
    print(username)
39
    rc_util.add_account(username, email, fullname, reason)
root's avatar
root committed
40
41
    print('sent account info')
    print('Waiting for completion...')
Krish Moodbidri's avatar
Krish Moodbidri committed
42
    rc_util.consume(username, routing_key=f'complete.{username}', callback=callback)