Skip to content
Snippets Groups Projects

Feat pre commit hook

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