Forked from
rc / rabbitmq_agents
489 commits behind the upstream repository.
-
Bo-Chun Chen authored9b19d748
rc_util.py 1.02 KiB
from rc_rmq import RCRMQ
import json
rc_rmq = RCRMQ({'exchange': 'Request'})
confirm_rmq = RCRMQ({'exchange': 'Confirm'})
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_account',
'msg': {
"username": username,
"fullname": full,
"reason": reason
}
})
def worker(ch, method, properties, body):
msg = json.loads(body)
task = msg['task']
print("get msg: {}".format(task))
tasks[task] = msg['success']
# Check if all tasks are done
done = True
for key, status in tasks.items():
if not status:
done = False
if done:
confirm_rmq.stop_consume()
confirm_rmq.delete_queue()
def consume(username, callback, debug=False):
if debug:
sleep(5)
else:
confirm_rmq.start_consume({
'queue': username,
'cb': callback
})
return { 'success' : True }