示例#1
0
 def process_submit_sm_event(self, message_id, event_type, remote_id,
                             command_status):
     if event_type == 'ack':
         yield self.message_stash.delete_cached_message(message_id)
         yield self.message_stash.expire_multipart_info(message_id)
         if not self.disable_ack:
             yield self.publish_ack(message_id, remote_id)
     else:
         if event_type != 'fail':
             self.log.warning(
                 "Unexpected multipart event type %r, assuming 'fail'" %
                 (event_type, ))
         err_msg = yield self.message_stash.get_cached_message(message_id)
         command_status = command_status or 'Unspecified'
         if err_msg is None:
             self.log.warning("Could not retrieve failed message: %s" %
                              (message_id, ))
         else:
             yield self.message_stash.delete_cached_message(message_id)
             yield self.message_stash.expire_multipart_info(message_id)
             yield self.publish_nack(message_id, command_status)
             yield self.failure_publisher.publish_message(
                 FailureMessage(message=err_msg.payload,
                                failure_code=None,
                                reason=command_status))
示例#2
0
 def mkmsg_fail(self,
                message,
                reason,
                failure_code=FailureMessage.FC_UNSPECIFIED):
     return FailureMessage(
         timestamp=datetime.now(),
         failure_code=failure_code,
         message=message,
         reason=reason,
     )
示例#3
0
文件: transport.py 项目: snopoke/vumi
 def submit_sm_failure(self, sent_sms_id, reason, failure_code=None):
     error_message = self.r_get_message(sent_sms_id)
     if error_message is None:
         log.err("Could not retrieve failed message:%s" % (sent_sms_id))
     else:
         self.r_delete_message(sent_sms_id)
         self.failure_publisher.publish_message(
             FailureMessage(message=error_message.payload,
                            failure_code=None,
                            reason=reason))
示例#4
0
 def test_get_dispatched_failures_no_connector(self):
     """
     .get_dispatched_failures() should use the default connector if none is
     passed in.
     """
     tx_helper = TransportHelper(Transport, transport_name='fooconn')
     dispatched = tx_helper.get_dispatched_failures()
     self.assertEqual(dispatched, [])
     msg = FailureMessage(
         message=tx_helper.msg_helper.make_outbound('foo').payload,
         failure_code=FailureMessage.FC_UNSPECIFIED, reason='sadness')
     self._add_to_dispatched(
         tx_helper.worker_helper.broker, 'fooconn.failures', msg)
     dispatched = tx_helper.get_dispatched_failures()
     self.assertEqual(dispatched, [msg])
示例#5
0
 def test_get_dispatched_failures(self):
     """
     .get_dispatched_failures() should get failures dispatched by the
     transport.
     """
     tx_helper = TransportHelper(Transport)
     dispatched = tx_helper.get_dispatched_failures('fooconn')
     self.assertEqual(dispatched, [])
     msg = FailureMessage(
         message=tx_helper.msg_helper.make_outbound('foo').payload,
         failure_code=FailureMessage.FC_UNSPECIFIED, reason='sadness')
     self._add_to_dispatched(
         tx_helper.worker_helper.broker, 'fooconn.failures', msg)
     dispatched = tx_helper.get_dispatched_failures('fooconn')
     self.assertEqual(dispatched, [msg])
示例#6
0
 def send_failure(self, message, exception, traceback):
     """Send a failure report."""
     try:
         failure_code = getattr(exception, "failure_code",
                                FailureMessage.FC_UNSPECIFIED)
         failure_msg = FailureMessage(message=message.payload,
                                      failure_code=failure_code,
                                      reason=traceback)
         d = self._middlewares.apply_publish("failure", failure_msg,
                                             self.transport_name)
         d.addCallback(self.failure_publisher.publish_message)
         d.addCallback(lambda _f: self.failure_published())
     except:
         log.err("Error publishing failure: %s, %s, %s" %
                 (message, exception, traceback))
         raise
     return d
示例#7
0
    def test_failure(self):
        mw = yield self.get_middleware({'op_mode': 'passive'})
        for failure in ['permanent', 'temporary', None]:
            fail_msg = FailureMessage(message='foo',
                                      failure_code=failure,
                                      reason='bar')
            mw.handle_failure(fail_msg, 'dummy_endpoint')

        def metric_name(status):
            return 'dummy_endpoint.failure.%s.counter' % (status, )

        [permanent] = mw.metric_manager[metric_name('permanent')].poll()
        [temporary] = mw.metric_manager[metric_name('temporary')].poll()
        [unspecified] = mw.metric_manager[metric_name('unspecified')].poll()
        self.assertEqual(permanent[1], 1)
        self.assertEqual(temporary[1], 1)
        self.assertEqual(unspecified[1], 1)