models.py 797 Bytes
Newer Older
1

2
3
4
5
from django.dispatch import receiver
from .. import models
from .serializers import DeploymentSerializer
import json
Lukas Burgey's avatar
Lukas Burgey committed
6
from .pubsub import PubSubConnection
7
8


Lukas Burgey's avatar
Lukas Burgey committed
9
10
11
12
class Deployments:
    pass


13
@receiver(models.deployment_change, sender=models.Deployment)
14
15
16
def publish_deployment(sender, instance=None, created=False, **kwargs):
    if instance is None:
        return
17

18
19
    message = json.dumps(DeploymentSerializer(instance).data)

20
21
22
    confirmed, online_sites = PubSubConnection().publish_by_service(
            instance.service, message)
    if confirmed:
Lukas Burgey's avatar
Lukas Burgey committed
23
        # delivery successful
24
25
26
27
28
29
        for site in online_sites:
            print('Client for site {} got update for service {}'.format(
                site,
                instance.service,
                ))
            site.client_updated()