Skip to content
Snippets Groups Projects
Commit f3f5d23f authored by Mitchell Moore's avatar Mitchell Moore
Browse files

implement rabbitmq casll option/script call option

parent c10c702e
No related branches found
No related tags found
No related merge requests found
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
import os import os
import time import time
import pika import pika
import sys from flask_socketio import SocketIO
from app import create_app from app import create_app
from flask_socketio import SocketIO
from flask import flash
config_name = os.getenv('FLASK_CONFIG') config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name) app = create_app(config_name)
...@@ -41,6 +40,12 @@ def check_dir(user, interval): ...@@ -41,6 +40,12 @@ def check_dir(user, interval):
return False return False
def create_account(username, fullname, reason):
# Todo: Ravi's and Louis's code go here
time.sleep(5)
return True
@socketio.on('user connect') @socketio.on('user connect')
def handle_my_custom_event(json, methods=['GET', 'POST']): def handle_my_custom_event(json, methods=['GET', 'POST']):
username = json["user"] username = json["user"]
...@@ -51,28 +56,34 @@ def handle_my_custom_event(json, methods=['GET', 'POST']): ...@@ -51,28 +56,34 @@ def handle_my_custom_event(json, methods=['GET', 'POST']):
def ingest_data(json, methods=['GET', 'POST']): def ingest_data(json, methods=['GET', 'POST']):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json)) print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
# Begin RabbitMQ process. # RabbitMQ Request Approach
credentials = pika.PlainCredentials('reggie', 'reggie') try:
parameters = pika.ConnectionParameters('ood', credentials = pika.PlainCredentials('reggie', 'reggie')
5672, parameters = pika.ConnectionParameters('ood',
'/', 5672,
credentials) '/',
credentials)
connection = pika.BlockingConnection(parameters) connection = pika.BlockingConnection(parameters)
channel = connection.channel() channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct') channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
node = sys.argv[1] if len(sys.argv) > 1 else 'info' node = 'ood'
message = ' '.join(sys.argv[2:]) or 'Hello World!' message = str(json)
channel.basic_publish(
exchange='direct_logs', routing_key=node, body=message)
print(" [x] Sent %r:%r" % (node, message))
connection.close() channel.basic_publish(
exchange='direct_logs', routing_key=node, body=message)
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + json["username"] + ' added to queue')
socketio.emit("creating account")
connection.close()
except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
socketio.emit("Account creation failed")
# Todo: Make the remaining portion of this method in a RabbitMQ consumer
# try: # try:
# fullname = json["fullname"] # fullname = json["fullname"]
...@@ -102,11 +113,14 @@ def ingest_data(json, methods=['GET', 'POST']): ...@@ -102,11 +113,14 @@ def ingest_data(json, methods=['GET', 'POST']):
@socketio.on("validate creation") @socketio.on("validate creation")
def creation_confirmation(json, methods=['GET', 'POST']): def creation_confirmation(json, methods=['GET', 'POST']):
# Todo: Make this mthod in a RabbitMQ consumer
# User create Script Approach
username = json["username"] username = json["username"]
fullname = json["fullname"]
reason = json["reason"]
if check_dir(username, 10): if create_account(username, fullname, reason):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username) print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
socketio.emit("Account created") socketio.emit("Account created")
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment