Пример #1
0
def process_messages_for_lambda_consumer(lambda_event: dict) -> None:
    for record in lambda_event['Records']:
        settings.HEDWIG_PRE_PROCESS_HOOK(sns_record=record)

        message_handler_lambda(record)

        settings.HEDWIG_POST_PROCESS_HOOK(sns_record=record)
Пример #2
0
def fetch_and_process_messages(queue_name: str,
                               queue,
                               num_messages: int = 1,
                               visibility_timeout: int = None) -> None:

    for queue_message in get_queue_messages(
            queue,
            num_messages=num_messages,
            visibility_timeout=visibility_timeout):
        settings.HEDWIG_PRE_PROCESS_HOOK(sqs_queue_message=queue_message)

        try:
            message_handler_sqs(queue_message)
        except RetryException as e:
            # Retry without logging exception
            extra = (e.extra if isinstance(e, LoggingError) else None)
            logger.info('Retrying due to exception', extra=extra)
        except Exception as e:
            extra = (e.extra if isinstance(e, LoggingError) else None)
            logger.exception(
                f'Exception while processing message from {queue_name}',
                extra=extra)
        else:
            try:
                queue_message.delete()
            except Exception:
                logger.exception(
                    f'Exception while deleting message from {queue_name}')
Пример #3
0
def fetch_and_process_messages(
        queue_name: str,
        queue,
        num_messages: int = 1,
        visibility_timeout: typing.Optional[int] = None) -> None:

    for queue_message in get_queue_messages(
            queue,
            num_messages=num_messages,
            visibility_timeout=visibility_timeout):
        settings.HEDWIG_PRE_PROCESS_HOOK(sqs_queue_message=queue_message)

        try:
            message_handler_sqs(queue_message)
            try:
                settings.HEDWIG_POST_PROCESS_HOOK(
                    sqs_queue_message=queue_message)
            except Exception:
                logger.exception(
                    f'Exception in post process hook for message from {queue_name}'
                )
                raise
            try:
                queue_message.delete()
            except Exception:
                logger.exception(
                    f'Exception while deleting message from {queue_name}')
        except Exception:
            # already logged in message_handler
            pass
Пример #4
0
def dispatch_mock_sqs_message(message: Message) -> None:
    from hedwig import consumer

    sqs_message = mock.Mock()
    sqs_message.body = json.dumps(message.as_dict())
    sqs_message.receipt_handle = 'test-receipt'
    settings.HEDWIG_PRE_PROCESS_HOOK(sqs_queue_message=sqs_message)
    consumer.message_handler_sqs(sqs_message)
Пример #5
0
def process_messages_for_lambda_consumer(lambda_event: dict) -> None:
    for record in lambda_event['Records']:
        settings.HEDWIG_PRE_PROCESS_HOOK(sns_record=record)

        try:
            message_handler_lambda(record)
        except Exception as e:
            extra = (e.extra if isinstance(e, LoggingError) else None)
            logger.exception('Exception while processing message', extra=extra)
            # let it bubble up so message ends up in DLQ
            raise