Skip to content
Snippets Groups Projects
Commit 9be2f281 authored by Ravi Tripathi's avatar Ravi Tripathi
Browse files

add on_message_callback function, and start consuming messages

parent 1fd19ccf
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import pika # python client
import sys
import rabbit_config as rcfg
import socket
import subprocess
import time
hostname = socket.gethostname().split(".", 1)[0]
......@@ -30,3 +30,30 @@ result = channel.queue_declare(queue=queue_name, exclusive=False)
channel.queue_bind(exchange=rcfg.Exchange, queue=queue_name, routing_key=queue_name)
def slurm_account_create(ch, method, properties, body):
msg = json.loads(body)
username = msg['username']
try:
subprocess.call(["sacctmgr", "add", "account", username, "Descripition: Add user"])
except:
print("Failed to create user")
channel.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_publish(exchange=rcfg.Exchange, routing_key='warewulf_file_sync', body=json.dumps(msg))
# ingest messages
channel.basic_consume(queue=queue_name, on_message_callback=slurm_account_create)
# initiate message ingestion
try:
channel.start_consuming()
except KeyboardInterrupt:
print("Disconnecting from broker.")
channel.stop_consuming()
connection.close()
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