Commit 84cfaeb7 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Fix delivery confirmation

parent a8ace825
......@@ -17,4 +17,10 @@ def publish_deployment(sender, instance=None, created=False, **kwargs):
message = json.dumps(DeploymentSerializer(instance).data)
PubSubConnection().publish_by_service(instance.service, message)
if PubSubConnection().publish_by_service(
instance.service, message):
# delivery successful
instance.service.site.client_updated()
print('client updated')
else:
print('client update failed')
......@@ -6,6 +6,12 @@ class PubSubConnection:
def __init__(self):
self.host = 'localhost'
self.exchange_name = 'deployments'
self.properties = pika.BasicProperties(
delivery_mode=1,
)
def delivery_callback(method):
print(str(method))
def connect(self):
self.connection = pika.BlockingConnection(
......@@ -14,7 +20,12 @@ class PubSubConnection:
self.channel = self.connection.channel()
self.channel.exchange_declare(
exchange=self.exchange_name,
durable=True,
exchange_type='topic')
self.channel.confirm_delivery()
# self.channel.confirm_delivery(
# callback=self.delivery_callback,
# )
def disconnect(self):
self.connection.close()
......@@ -24,11 +35,16 @@ class PubSubConnection:
def publish_by_service(self, service, message):
self.connect()
self.channel.basic_publish(
print(' [x] Sent {}:{}'.format(
self.service_routing_key(service), message))
# True if the client acked the message
delivery_confirmed = self.channel.basic_publish(
exchange=self.exchange_name,
routing_key=self.service_routing_key(service),
body=message)
body=message,
properties=self.properties,
)
print(' [x] Sent {}:{}'.format(
self.service_routing_key(service), message))
self.disconnect()
return delivery_confirmed
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment