Skip to content

Commit edf584f

Browse files
committed
added RabbitMQ grow_simulator queue
1 parent 78eb2d4 commit edf584f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ nwn_client = NwnClient(postgres_config, rabbitmq_config)
4242
try:
4343
nwn_client.connect()
4444
job_id1: uuid4 = nwn_client.start_work_flow(
45-
WorkFlowType.GROWTH_OPTIMIZER, "test_job1", "esdl_string", "test_user1", "test_proj"
45+
WorkFlowType.GROW_OPTIMIZER, "test_job1", "esdl_string", "test_user1", "test_proj"
4646
)
4747
job_id2: uuid4 = nwn_client.start_work_flow(
48-
WorkFlowType.GROWTH_OPTIMIZER, "test_job2", "esdl_string", "test_user2", "test_proj"
48+
WorkFlowType.GROW_OPTIMIZER, "test_job2", "esdl_string", "test_user2", "test_proj"
4949
)
5050
print(job_id1)
5151

src/nwnsdk/rabbitmq/rabbitmq_client.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424

2525
class Queue(Enum):
2626
StartWorkflowOptimizer = "start_work_flow.optimizer"
27+
StartWorkflowGrowSimulator = "start_work_flow.grow_simulator"
2728

2829
@staticmethod
2930
def from_workflow_type(workflow_type: WorkFlowType) -> "Queue":
30-
if workflow_type == WorkFlowType.GROWTH_OPTIMIZER:
31+
if workflow_type == WorkFlowType.GROW_OPTIMIZER:
3132
return Queue.StartWorkflowOptimizer
33+
elif workflow_type == WorkFlowType.GROW_SIMULATOR:
34+
return Queue.StartWorkflowGrowSimulator
3235
else:
3336
raise RuntimeError(f"Unimplemented workflow type {workflow_type}. Please implement.")
3437

@@ -71,8 +74,9 @@ def _connect_rabbitmq(self):
7174
self.channel = self.connection.channel()
7275
self.channel.basic_qos(prefetch_size=0, prefetch_count=1)
7376
self.channel.exchange_declare(exchange=self.rabbitmq_exchange, exchange_type="topic")
74-
self.queue = self.channel.queue_declare(Queue.StartWorkflowOptimizer.value, exclusive=False).method.queue
75-
self.channel.queue_bind(self.queue, self.rabbitmq_exchange, routing_key=Queue.StartWorkflowOptimizer.value)
77+
for queue_item in Queue:
78+
queue = self.channel.queue_declare(queue_item.value, exclusive=False).method.queue
79+
self.channel.queue_bind(queue, self.rabbitmq_exchange, routing_key=queue_item.value)
7680
LOGGER.info("Connected to RabbitMQ")
7781

7882
def _start_rabbitmq(self):
@@ -81,9 +85,9 @@ def _start_rabbitmq(self):
8185

8286
def set_callbacks(self, callbacks: Dict[Queue, PikaCallback]):
8387
for queue, callback in callbacks.items():
84-
self.connection.add_callback_threadsafe(lambda: self.channel.basic_consume(queue=queue.value,
85-
on_message_callback=callback,
86-
auto_ack=False))
88+
self.connection.add_callback_threadsafe(
89+
lambda: self.channel.basic_consume(queue=queue.value, on_message_callback=callback, auto_ack=False)
90+
)
8791

8892
def run(self):
8993
self.rabbitmq_is_running = True
@@ -107,9 +111,9 @@ def _send_start_work_flow(self, job_id: uuid4, work_flow_type: WorkFlowType):
107111

108112
def _send_output(self, queue: Queue, message: str):
109113
body: bytes = message.encode("utf-8")
110-
self.connection.add_callback_threadsafe(lambda: self.channel.basic_publish(exchange=self.rabbitmq_exchange,
111-
routing_key=queue.value,
112-
body=body))
114+
self.connection.add_callback_threadsafe(
115+
lambda: self.channel.basic_publish(exchange=self.rabbitmq_exchange, routing_key=queue.value, body=body)
116+
)
113117

114118
def _stop_rabbitmq(self):
115119
self.rabbitmq_is_running = False

0 commit comments

Comments
 (0)