Beispiel #1
0
 def process_line(self, line):
     data = {
         'transport_name': self.transport_name,
         'transport_metadata': {},
     }
     data.update(json.loads(line))
     self.publisher.publish_message(TransportUserMessage(**to_kwargs(data)))
Beispiel #2
0
 def handle_raw_inbound_event(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportEvent(_process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_event(msg)
         request.finish()
         if msg.payload["event_type"] == "ack":
             self.update_status(
                 status='ok', component='sent-by-vumi-go',
                 type='vumi_go_sent', message='Sent by Vumi Go')
         elif msg.payload["event_type"] == "nack":
             self.update_status(
                 status='down', component='sent-by-vumi-go',
                 type='vumi_go_failed', message='Vumi Go failed to send')
         self.update_status(
             status='ok', component='vumi-go-event',
             type='good_request',
             message='Good event received from Vumi Go')
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
         self.update_status(
             status='down', component='vumi-go-event',
             type='bad_request', message='Bad event received from Vumi Go')
Beispiel #3
0
 def handle_raw_inbound_event(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportEvent(_process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_event(msg)
         request.finish()
         if msg.payload["event_type"] == "ack":
             self.update_status(status='ok',
                                component='sent-by-vumi-go',
                                type='vumi_go_sent',
                                message='Sent by Vumi Go')
         elif msg.payload["event_type"] == "nack":
             self.update_status(status='down',
                                component='sent-by-vumi-go',
                                type='vumi_go_failed',
                                message='Vumi Go failed to send')
         self.update_status(status='ok',
                            component='vumi-go-event',
                            type='good_request',
                            message='Good event received from Vumi Go')
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
         self.update_status(status='down',
                            component='vumi-go-event',
                            type='bad_request',
                            message='Bad event received from Vumi Go')
Beispiel #4
0
 def assertDelivered(self, message):
     delivered_messages = [
         TransportUserMessage(**to_kwargs(payload))
         for _, payload in self._delivery_history
     ]
     self.assertIn(message['message_id'],
                   [msg['message_id'] for msg in delivered_messages])
Beispiel #5
0
 def process_line(self, line):
     data = {
         'transport_name': self.transport_name,
         'transport_metadata': {},
     }
     data.update(json.loads(line))
     self.publisher.publish_message(
         TransportUserMessage(**to_kwargs(data)))
Beispiel #6
0
 def handle_raw_inbound_message(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportUserMessage(_process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_message(msg)
         request.finish()
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
Beispiel #7
0
 def handle_raw_inbound_message(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportUserMessage(_process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_message(msg)
         request.finish()
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
Beispiel #8
0
 def lineReceived(self, line):
     d = Deferred()
     d.addCallback(self.callback)
     d.addErrback(self.errback)
     line = line.strip()
     try:
         data = json.loads(line)
         d.callback(self.message_class(
             _process_fields=True, **to_kwargs(data)))
     except ValueError, e:
         f = Failure(VumiBridgeInvalidJsonError(line))
         d.errback(f)
Beispiel #9
0
 def lineReceived(self, line):
     d = Deferred()
     d.addCallback(self.callback)
     d.addErrback(self.errback)
     line = line.strip()
     try:
         data = json.loads(line)
         d.callback(
             self.message_class(_process_fields=True, **to_kwargs(data)))
     except ValueError, e:
         f = Failure(VumiBridgeInvalidJsonError(line))
         d.errback(f)
Beispiel #10
0
 def get_value(self, modelobj):
     """Get the value associated with this descriptor."""
     payload = {}
     for key, value in modelobj._riak_object.get_data().iteritems():
         if key.startswith(self.prefix):
             key = key[len(self.prefix):]
             # TODO: timestamp as datetime in payload must die.
             if key == "timestamp":
                 value = self._timestamp_from_json(value)
             payload[key] = value
     if not payload:
         return None
     return self.field.message_class(**to_kwargs(payload))
Beispiel #11
0
 def get_value(self, modelobj):
     """Get the value associated with this descriptor."""
     payload = {}
     for key, value in modelobj._riak_object.get_data().iteritems():
         if key.startswith(self.prefix):
             key = key[len(self.prefix):]
             # TODO: timestamp as datetime in payload must die.
             if key == "timestamp":
                 value = self._timestamp_from_json(value)
             payload[key] = value
     if not payload:
         return None
     return self.field.message_class(**to_kwargs(payload))
Beispiel #12
0
 def handle_raw_inbound_message(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportUserMessage(
             _process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_message(msg)
         request.finish()
         self.update_status(
             status='ok', component='received-from-vumi-go',
             type='good_request', message='Good request received')
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
         self.update_status(
             status='down', component='received-from-vumi-go',
             type='bad_request', message='Bad request received')
Beispiel #13
0
 def handle_raw_inbound_message(self, request):
     try:
         data = json.loads(request.content.read())
         msg = TransportUserMessage(_process_fields=True, **to_kwargs(data))
         yield self.handle_inbound_message(msg)
         request.finish()
         self.update_status(status='ok',
                            component='received-from-vumi-go',
                            type='good_request',
                            message='Good request received')
     except Exception as e:
         log.err(e)
         request.setResponseCode(400)
         request.finish()
         self.update_status(status='down',
                            component='received-from-vumi-go',
                            type='bad_request',
                            message='Bad request received')
Beispiel #14
0
 def from_json(cls, json_string):
     return cls(_process_fields=False, **to_kwargs(from_json(json_string)))
Beispiel #15
0
 def from_json(cls, json_string):
     return cls(_process_fields=False, **to_kwargs(from_json(json_string)))
Beispiel #16
0
 def get_response_msgs(self, response):
     payloads = from_json(response.delivered_body)
     return [
         TransportUserMessage(_process_fields=False, **to_kwargs(payload))
         for payload in payloads
     ]
Beispiel #17
0
 def from_json(cls, json_string):
     # We override this to avoid the datetime conversions.
     return cls(_process_fields=False, **to_kwargs(json.loads(json_string)))
Beispiel #18
0
 def get_response_msgs(self, response):
     payloads = from_json(response.delivered_body)
     return [TransportUserMessage(
             _process_fields=False, **to_kwargs(payload))
             for payload in payloads]
Beispiel #19
0
 def assertDelivered(self, message):
     delivered_messages = [TransportUserMessage(**to_kwargs(payload))
                             for _, payload in self._delivery_history]
     self.assertIn(message['message_id'],
         [msg['message_id'] for msg in delivered_messages])