Commit 06512aa2 authored by Mitchell Moore's avatar Mitchell Moore Committed by Krish Moodbidri
Browse files

Update to create account via rabbitmq calls to test producer scripts on ohpc and ood

- Add timestamps to server logs
- Add rough Todo comments for RabbitMQ implementation
- Update imports
- Add tutorial code with routing capability
- Update comment
- Complete base producer for ohpc/ood
- Duplicate producer code for in app testing
- Implement rabbitmq call option/script call option
- Create placeholder functions for acct. creation. Remove producer
- Check for creation
- Remove sleep in creation. Define goals for confirm function
parent ab533531
import os
import time
import pika
from flask_socketio import SocketIO
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
socketio = SocketIO(app)
def messageReceived(methods=['GET', 'POST']):
print('message was received!!!')
def check_dir(user, interval):
# Todo: Make this mothod in a consumer
:param user: (string) username to check for in DB.
:param interval: (int) Frequency to check in seconds.
:return: (boolean) if account has been registered.
seconds = 0
while seconds < 600:
querystring = "_" + user + ".done"
for filename in os.listdir("flat_db/"):
if filename.endswith(querystring):
return True
seconds = seconds + interval
return False
def create_account(username, fullname, reason):
# Todo: Ravi's and Louis's code go here
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
socketio.emit("creating account")
def account_confirmation(username):
# Todo: Code to create a consumer based on the username goes here
# Todo: Goal is to have it listening for confirmation.
return True
@socketio.on('user connect')
def handle_my_custom_event(json, methods=['GET', 'POST']):
username = json["user"]
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' connected.')
@socketio.on('user data')
def ingest_data(json, methods=['GET', 'POST']):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
create_account(json['username'], json['fullname'], json['reason'])
except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
socketio.emit("Account creation failed")
@socketio.on("validate creation")
def creation_confirmation(json, methods=['GET', 'POST']):
# User create Script Approach
username = json["username"]
if account_confirmation(username):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username)
socketio.emit("Account created")
socketio.emit("Account creation failed")
if __name__ == '__main__':
Markdown is supported
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