Commit a7358eec authored by Krish Moodbidri's avatar Krish Moodbidri
Browse files

added timeout function

parent b84cd7e2
...@@ -2,6 +2,7 @@ import vars ...@@ -2,6 +2,7 @@ import vars
import sys import sys
import json import json
import time import time
import signal
from celery import Celery from celery import Celery
from flask_socketio import SocketIO from flask_socketio import SocketIO
...@@ -13,6 +14,7 @@ broker_url = vars.broker_url ...@@ -13,6 +14,7 @@ broker_url = vars.broker_url
celery = Celery('flask_user_reg', broker=broker_url) celery = Celery('flask_user_reg', broker=broker_url)
socketio = SocketIO(message_queue=vars.message_queue) socketio = SocketIO(message_queue=vars.message_queue)
timeout = 60
def callback(channel, method, properties, body): def callback(channel, method, properties, body):
msg = json.loads(body) msg = json.loads(body)
...@@ -33,6 +35,9 @@ def send_msg(event, room): ...@@ -33,6 +35,9 @@ def send_msg(event, room):
print("Post '{}' to room '{}'".format(event,room)) print("Post '{}' to room '{}'".format(event,room))
socketio.emit(event, room=room) socketio.emit(event, room=room)
def timeout_handler(signum, frame):
print("Process timeout, there's might some issue with agents")
rc_util.rc_rmq.stop_consume()
@celery.task @celery.task
def celery_create_account(json, session): def celery_create_account(json, session):
...@@ -47,6 +52,12 @@ def celery_create_account(json, session): ...@@ -47,6 +52,12 @@ def celery_create_account(json, session):
print(username) print(username)
rc_util.add_account(username, email, fullname, reason) rc_util.add_account(username, email, fullname, reason)
print('sent account info') print('sent account info')
# Set initial timeout timer
signal.signal(signal.SIGALRM, timeout_handler)
signal.setitimer(signal.ITIMER_REAL, timeout)
print('Waiting for completion...') print('Waiting for completion...')
rc_util.consume(username, routing_key=f'complete.{username}', callback=callback) rc_util.consume(username, routing_key=f'complete.{username}', callback=callback)
send_msg('account ready', room) send_msg('account ready', room)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment