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)))
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')
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')
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])
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)))
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()
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)
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)
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))
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')
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')
def from_json(cls, json_string): return cls(_process_fields=False, **to_kwargs(from_json(json_string)))
def get_response_msgs(self, response): payloads = from_json(response.delivered_body) return [ TransportUserMessage(_process_fields=False, **to_kwargs(payload)) for payload in payloads ]
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)))
def get_response_msgs(self, response): payloads = from_json(response.delivered_body) return [TransportUserMessage( _process_fields=False, **to_kwargs(payload)) for payload in payloads]
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])