def publish(self, model_or_models): if isinstance(model_or_models, QuerySet): models = list(model_or_models) elif not isinstance(model_or_models, list): models = [model_or_models] else: models = model_or_models model = models[0] serializer_class = serializers.MAPPING[type(model)] msg = json.dumps({ 'type': type(model).__name__, 'models': serializer_class(models, many=True).data }) self.log.debug('publishing change "%s": %s', msg) redis_client.publish('model_changes', msg)
def __str__(self): return json.dumps(self.data)
def work(self): redis_client.publish('monitoring', json.dumps({'type': 'beacon'}))