tasks.py 1.49 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

19

20
21
22
def send_msg(event, room):
   print("Post '{}' to room '{}'".format(event,room))
   socketio.emit(event, room=room)
23

24

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

33
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
34
    send_msg('creating account', room)
35
    print(username)
36
    rc_util.add_account(username, email, fullname, reason)
root's avatar
root committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    print('sent account info')

#       rc_util.consume(username)
#       print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
#       send_msg('account ready', room)
#    return 

#rc_util.add_account(args.username, email=args.email, full=args.full_name, reason=args.reason)
#print(f'Account for {args.username} requested.')

# Set initial timeout timer
    signal.signal(signal.SIGALRM, timeout_handler)
    signal.setitimer(signal.ITIMER_REAL, timeout)

    print('Waiting for completion...')
    rc_util.consume(args.username, routing_key=f'complete.{args.username}', callback=callback)