Commit 946da517 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add publishing of deployment changes

parent 2d9d1701
from django.dispatch import receiver
from django.db.models.signals import post_save
from .. import models
from .serializers import DeploymentSerializer
import pika
import json
class Deployments:
# attributes: services
pass
@receiver(post_save, sender=models.Deployment)
def publish_deployment(sender, instance=None, created=False, **kwargs):
if instance is None:
return
class UserDeployment:
# attributes: user, ssh_keys
pass
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
exchange_name = 'deployments'
channel.exchange_declare(exchange=exchange_name,
exchange_type='topic')
message = json.dumps(DeploymentSerializer(instance).data)
# we only use the service as routing key
routing_keys = ['service.' + instance.service.name]
for routing_key in routing_keys:
channel.basic_publish(exchange=exchange_name,
routing_key=routing_key,
body=message)
print(" [x] Sent %r:%r" % (routing_key, message))
connection.close()
......@@ -15,7 +15,7 @@ class UserSerializer(serializers.ModelSerializer):
]
class UserDeploymentSerializer(serializers.ModelSerializer):
class DeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
ssh_keys = frontend_serializers.SSHPublicKeySerializer(many=True)
......@@ -27,6 +27,6 @@ class UserDeploymentSerializer(serializers.ModelSerializer):
class DeploymentsSerializer(serializers.Serializer):
services = serializers.DictField(
child=serializers.ListField(
child=UserDeploymentSerializer()
child=DeploymentSerializer()
)
)
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