
* À terme, il sera ajouté aux bindings, dans l'objectif de gérer les envois de modifications sans que ceux-ci n'aient à implémenter la moindre autre chose qu'un producer standard qui balance des diff d'objets.
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
#!/bin/bash /usr/scripts/python.sh
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Trigger library, designed to send events messages.
|
|
#
|
|
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
|
# License : GPLv3
|
|
# Date : 18/05/2014
|
|
|
|
import cmb
|
|
import cPickle
|
|
import gestion.config.trigger as trigger_config
|
|
import cranslib.clogger as clogger
|
|
import pika
|
|
|
|
logger = clogger.CLogger("trigger", "info")
|
|
|
|
class Event(cmb.BasicProducer):
|
|
"""
|
|
Event tracker
|
|
"""
|
|
def __init__(self, app_id):
|
|
"""Extended
|
|
|
|
"""
|
|
logger.info("Starting trigger Event program…")
|
|
super(Event, self).__init__(trigger_config.master, 'trigger.event', app_id)
|
|
self._connection = self.connect()
|
|
self.get_chan()
|
|
|
|
def send_message(self, routing_key, body):
|
|
"""Sends basic message with app_id and body
|
|
|
|
"""
|
|
try:
|
|
logger.info("Sending message %s with routing_key %s.", body, routing_key)
|
|
body = cPickle.dumps(body)
|
|
self._channel.basic_publish(exchange=self._exchange_name,
|
|
routing_key=routing_key,
|
|
body=body,
|
|
properties=pika.BasicProperties(
|
|
delivery_mode=2,
|
|
app_id=self._app_id,
|
|
))
|
|
except:
|
|
print "Failure in trigger.event"
|
|
raise
|
|
|
|
def announce(self, body):
|
|
self.send_message("trigger.announce", body)
|