Skip to content
Snippets Groups Projects
Commit 51f38b21 authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Add rc_util.py

including add_account and consume function
parent 57077478
No related branches found
No related tags found
2 merge requests!23Feat resolve uid gid,!9Feat connection module
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 }
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