Commit af181795 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Move a receiver

parent f3029375
from django.dispatch import receiver
from .. import models
from .serializers import DeploymentSerializer
import json
class Deployments:
pass
@receiver(models.deployment_change, sender=models.Deployment)
def publish_deployment(sender, instance=None, created=False, **kwargs):
if instance is None:
return
message = json.dumps(DeploymentSerializer(instance).data)
confirmed, online_sites = models.rabbitmq_instance().publish_by_service(
instance.service, message)
if confirmed:
# delivery successful
for site in online_sites:
print('Client for site {} got update for service {}'.format(
site,
instance.service,
))
site.ack_update(service=instance.service)
......@@ -10,6 +10,7 @@ from datetime import datetime
import requests
from requests.auth import HTTPBasicAuth
import pika
import json
deployment_change = Signal(providing_args=['instance'])
......@@ -187,6 +188,7 @@ class RabbitMQInstance(models.Model):
def connect(self):
self.connection_properties = pika.ConnectionParameters(
host=self.host,
ssl=True,
)
self.connection = pika.BlockingConnection(self.connection_properties)
......@@ -523,3 +525,23 @@ def deregister_at_rabbitmq(
sender, instance=None, **kwargs):
RabbitMQInstance().deregister_site(instance)
@receiver(deployment_change, sender=Deployment)
def publish_deployment(sender, instance=None, created=False, **kwargs):
if instance is None:
return
from .clientapi.serializers import DeploymentSerializer
message = json.dumps(DeploymentSerializer(instance).data)
confirmed, online_sites = rabbitmq_instance().publish_by_service(
instance.service, message)
if confirmed:
# delivery successful
for site in online_sites:
print('Client for site {} got update for service {}'.format(
site,
instance.service,
))
site.ack_update(service=instance.service)
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