Skip to content
Snippets Groups Projects

Feat black config

Closed Bo-Chun Chen requested to merge github/fork/diedpigs/feat-black-config into feat-cod-rmq
8 files
+ 176
109
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -8,12 +8,13 @@ from rc_rmq import RCRMQ
task = "ohpc_account"
# Instantiate rabbitmq object
rc_rmq = RCRMQ({'exchange': 'RegUsr', 'exchange_type': 'topic'})
rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"})
def ohpc_account_create(ch, method, properties, body):
msg = json.loads(body)
print("Message received {}".format(msg))
username = msg['username']
username = msg["username"]
success = False
try:
subprocess.call(["sudo", "useradd", username])
@@ -24,28 +25,25 @@ def ohpc_account_create(ch, method, properties, body):
print("[{}]: Error: {}".format(task, e))
ch.basic_ack(delivery_tag=method.delivery_tag)
msg['uid'] = getpwnam(username).pw_uid
msg['gid'] = getpwnam(username).pw_gid
msg["uid"] = getpwnam(username).pw_uid
msg["gid"] = getpwnam(username).pw_gid
# send confirm message
rc_rmq.publish_msg({
'routing_key': 'confirm.' + username,
'msg': {
'task': task,
'success': success
rc_rmq.publish_msg(
{
"routing_key": "confirm." + username,
"msg": {"task": task, "success": success},
}
})
)
if success:
# send create message to other agent
rc_rmq.publish_msg({
'routing_key': 'create.' + username,
'msg': msg
})
rc_rmq.publish_msg(
{"routing_key": "create." + username, "msg": msg}
)
print("Start Listening to queue: {}".format(task))
rc_rmq.start_consume({
'queue': task,
'routing_key': 'request.*',
'cb': ohpc_account_create
})
rc_rmq.start_consume(
{"queue": task, "routing_key": "request.*", "cb": ohpc_account_create}
)
Loading