Exemple #1
0
async def handle_event(
        registry: registries.BaseRegistry,
        resource: registries.Resource,
        logger: Union[logging.LoggerAdapter, logging.Logger],
        patch: dict,
        event: dict,
):
    """
    Handle a received event, log but ignore all errors.

    This is a lightweight version of the cause handling, but for the raw events,
    without any progress persistence. Multi-step calls are also not supported.
    If the handler fails, it fails and is never retried.
    """
    handlers = registry.get_event_handlers(resource=resource, event=event)
    for handler in handlers:

        # The exceptions are handled locally and are not re-raised, to keep the operator running.
        try:
            logger.debug(f"Invoking handler {handler.id!r}.")

            # TODO: also set the context-vars, despite most of the make no sense here.
            result = await invocation.invoke(
                handler.fn,
                event=event,
                patch=patch,
                logger=logger,
            )

        except Exception:
            logger.exception(f"Handler {handler.id!r} failed with an exception. Will ignore.")

        else:
            logger.info(f"Handler {handler.id!r} succeeded.")
            status.store_result(patch=patch, handler=handler, result=result)
Exemple #2
0
def test_store_result(handler, expected, result):
    patch = {}
    store_result(patch=patch, handler=handler, result=result)
    assert patch == expected