示例#1
0
 def delete_message(self, receipt_handle):
     try:
         self._sqs_client.delete_message(QueueUrl=self._queue_url,
                                         ReceiptHandle=receipt_handle)
     except Exception as e:
         raise IntegrationError('Cannot remove message from SQS queue',
                                str(e))
    def create_trackor(self, data):
        fields = self._field_mappings.get_ready_fields_mapping(data)
        self._trackor.create(fields)
        if len(self._trackor.errors) > 0:
            raise IntegrationError('Cannot create Trackor',
                                   self._trackor.errors)

        return self._trackor.jsonData
示例#3
0
    def timestamp_to_datetime(self, value):
        try:
            sent_datetime = datetime.datetime.fromtimestamp(int(value) / 1000)
        except Exception as e:
            raise IntegrationError(
                'Cannot converted timestamp to datetime. Timestamp = {}'.
                format(value), str(e))

        return sent_datetime.strftime(self._datetime_format)
    def find_trackors(self, data):
        search_conditions = self._trackor_filter.get_ready_search_conditions(
            data)

        self._trackor.read(search=search_conditions, fields=['xitor_key'])
        if len(self._trackor.errors) > 0:
            raise IntegrationError('Error while filtering existing trackors',
                                   self._trackor.errors)

        return self._trackor.jsonData
    def get_attribute_value(self, attribute_path):
        value = self._message
        try:
            for attribute in attribute_path:
                value = value[attribute]
        except Exception as e:
            raise IntegrationError(
                'Cannot get message attribute value. Attribute [{}]'.format(
                    '. '.join(attribute_path)), str(e))

        return value
示例#6
0
    def get_value_part(self, value):
        if not self._value_regexp:
            return value

        value_part_list = re.findall(self._value_regexp, value)
        if not value_part_list:
            value_part = ''
        else:
            try:
                value_part = value_part_list[0]
            except Exception as e:
                raise IntegrationError(
                    'Cannot get value part. Value regexp = {}'.format(
                        self._value_regexp), str(e))

        if not isinstance(value_part, str):
            raise IntegrationError(
                'Value part is not a string.',
                'Value = {}; Value regexp = {}'.format(value,
                                                       self._value_regexp))
        return value_part
示例#7
0
    def get_messages(self):
        try:
            response = self._sqs_client.receive_message(
                QueueUrl=self._queue_url,
                AttributeNames=['SentTimestamp'],
                MessageAttributeNames=['All'],
                MaxNumberOfMessages=MessageQueueService.MAX_NUMBER_OF_MESSAGES,
                WaitTimeSeconds=self._wait_time_seconds)
        except Exception as e:
            raise IntegrationError('Cannot get messages from SQS queue',
                                   str(e))

        amazon_messages = []
        if 'Messages' in response:
            for message in response['Messages']:
                amazon_messages.append(AmazonMessage(message))

        return amazon_messages