tasks.py 998 Bytes
Newer Older
1
2
3
4
from celery import Celery
import time
from flask_socketio import SocketIO
import subprocess
5
import vars
6
import rc_util
7
8
9
10

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

11
broker_url = vars.broker_url
12
13
celery = Celery('flask_user_reg', broker=broker_url)

14
socketio = SocketIO(message_queue=vars.message_queue)
15

16

17
18
19
def send_msg(event, room):
   print("Post '{}' to room '{}'".format(event,room))
   socketio.emit(event, room=room)
20

21

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

30
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
31
    send_msg('creating account', room)
32
    print(username)
33
34
    rc_util.add_account(username, email, fullname, reason)
    rc_util.consume(username)
35
    print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
36
    send_msg('account ready', room)