Example #1
0
    def store_failure(self, message, reason, retry_delay=None):
        """
        Store this failure in redis, with an optional retry delay.

        :param message: The failed message.
        :param reason: A string containing the failure reason.
        :param retry_delay: The (optional) retry delay in seconds.

        If ``retry_delay`` is not ``None``, a retry will be scheduled
        approximately ``retry_delay`` seconds in the future.
        """
        message_json = message
        if not isinstance(message, basestring):
            # This isn't already JSON-encoded.
            message_json = to_json(message)
        key = self.failure_key()
        if not retry_delay:
            retry_delay = 0
        self.r_server.hmset(key, {
                "message": message_json,
                "reason": reason,
                "retry_delay": str(retry_delay),
                })
        self.add_to_failure_set(key)
        if retry_delay:
            self.store_retry(key, retry_delay)
        return key
Example #2
0
    def store_failure(self, message, reason, retry_delay=None):
        """
        Store this failure in redis, with an optional retry delay.

        :param message: The failed message.
        :param reason: A string containing the failure reason.
        :param retry_delay: The (optional) retry delay in seconds.

        If ``retry_delay`` is not ``None``, a retry will be scheduled
        approximately ``retry_delay`` seconds in the future.
        """
        message_json = message
        if not isinstance(message, basestring):
            # This isn't already JSON-encoded.
            message_json = to_json(message)
        key = self.failure_key()
        if not retry_delay:
            retry_delay = 0
        self.r_server.hmset(
            key, {
                "message": message_json,
                "reason": reason,
                "retry_delay": str(retry_delay),
            })
        self.add_to_failure_set(key)
        if retry_delay:
            self.store_retry(key, retry_delay)
        return key
Example #3
0
 def readline(self, line):
     match = self.log_pattern.match(line)
     if match:
         data = match.groupdict()
         date = datetime.datetime(**parse_date(data['date'],
                                     self.date_pattern))
         if self.start and self.start > date:
             return
         if self.stop and date > self.stop:
             return
         try:
             # JSON
             self.emit(to_json(json.loads(data['message'])))
         except:
             # Raw dict being printed
             self.emit(to_json(eval(data['message'])))
Example #4
0
 def test_to_json(self):
     data = {
         'foo': 1,
         'baz': {
             'a': 'b',
         }
     }
     self.assertEqual(json.loads(to_json(data)), data)
Example #5
0
 def test_to_json_supports_vumi_dates(self):
     timestamp = datetime(2015, 1, 2, 12, 01, 02, microsecond=134001)
     data = {
         'foo': timestamp,
     }
     self.assertEqual(json.loads(to_json(data)), {
         'foo': '2015-01-02 12:01:02.134001',
     })
Example #6
0
 def test_to_json(self):
     data = {
         'foo': 1,
         'baz': {
             'a': 'b',
         }
     }
     self.assertEqual(json.loads(to_json(data)), data)
Example #7
0
 def test_to_json_supports_vumi_dates(self):
     timestamp = datetime(
         2015, 1, 2, 12, 01, 02, microsecond=134001)
     data = {
         'foo': timestamp,
     }
     self.assertEqual(json.loads(to_json(data)), {
         'foo': '2015-01-02 12:01:02.134001',
     })
Example #8
0
    def test_store_message(self):
        '''Stores the message under the correct key'''
        store = yield self.create_store()
        msg = TransportUserMessage.send(to_addr='+213', content='foo')
        yield store.store_message('channel_id', api_from_message(msg))

        msg_json = yield self.redis.hget(
            'channel_id:outbound_messages:{}'.format(msg['message_id']),
            'message')
        self.assertEqual(msg_json, to_json(api_from_message(msg)))
Example #9
0
 def readline(self, line):
     match = self.log_pattern.match(line)
     if match:
         data = match.groupdict()
         date = datetime.datetime(**parse_date(data['date'],
                                     self.date_pattern))
         if self.start and self.start > date:
             return
         if self.stop and date > self.stop:
             return
         self.emit(to_json(eval(data['message'])))
Example #10
0
 def readline(self, line):
     match = self.log_pattern.match(line)
     if match:
         data = match.groupdict()
         date = datetime.datetime(
             **parse_date(data['date'], self.date_pattern))
         if self.start and self.start > date:
             return
         if self.stop and date > self.stop:
             return
         self.emit(to_json(eval(data['message'])))
Example #11
0
 def finish_request(self, request, msgs):
     request.setResponseCode(http.OK)
     request.write(to_json([msg.payload for msg in msgs]))
     request.finish()
Example #12
0
 def store_message(self, channel_id, message):
     '''Stores an outbound message'''
     key = self.get_key(channel_id, message['message_id'])
     return self.store_property(key, 'message', to_json(message))
Example #13
0
 def _put_common(self, table, row_id, family, pydata):
     """JSON-encode and update a set of values."""
     data = dict((k.encode('utf-8'), to_json(v)) for k, v
                 in pydata.items())
     return self._put_row(table, row_id, family, data)
Example #14
0
 def _put_common(self, table, row_id, family, pydata):
     """JSON-encode and update a set of values."""
     data = dict((k.encode('utf-8'), to_json(v)) for k, v in pydata.items())
     return self._put_row(table, row_id, family, data)
Example #15
0
 def store_message(self, channel_id, message):
     '''Stores an outbound message'''
     key = self.get_key(channel_id, message['message_id'])
     return self.store_property(key, 'message', to_json(message))