From 12de65f35b65847ca8f44494f852e1f8b61a9227 Mon Sep 17 00:00:00 2001 From: "Bo-Chun Louis Chen(VM)" <louistw@uab.edu> Date: Sat, 22 Feb 2020 05:00:28 +0000 Subject: [PATCH] Add rc_util.py including add_account and consume function --- rc_util.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 rc_util.py diff --git a/rc_util.py b/rc_util.py new file mode 100644 index 0000000..606d4a0 --- /dev/null +++ b/rc_util.py @@ -0,0 +1,42 @@ +from rc_rmq import RCRMQ +import json + +rc_rmq = RCRMQ({'exchange': 'RegUsr'}) +tasks = {'ohpc_account': False, 'ohpc_homedir': False, 'ood_account': False, 'slurm_account': False} + +def add_account(username, full='', reason=''): + rc_rmq.publish_msg({ + 'routing_key': 'ohpc', + 'msg': { + "username": username, + "fullname": full, + "reason": reason + } + }) + +def worker(ch, method, properties, body): + msg = json.loads(body) + task = msg['username'] + print("get msg: {}".format(task)) + + tasks[task] = True + ch.basic_ack(delivery_tag=method.delivery_tag) + + # Check if all tasks are done + done = True + for key, status in tasks.items(): + if not status: + done = False + if done: + rc_rmq.stop_consume() + +def consume(username, worker, debug=False): + if debug: + sleep(5) + else: + rc_rmq.start_consume({ + 'queue': username, + 'cb': worker + }) + + return { 'success' : True } -- GitLab