How to use the rele.middleware.run_middleware_hook function in rele

To help you get started, we’ve selected a few rele examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mercadona / rele / rele / subscription.py View on Github external
run_middleware_hook("post_process_message")
            return

        try:
            res = self._subscription(data, **dict(message.attributes))
        except Exception as e:
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
                start_time,
                message,
            )
        else:
            message.ack()
            run_middleware_hook(
                "post_process_message_success", self._subscription, start_time, message,
            )
            return res
        finally:
            run_middleware_hook("post_process_message")
github mercadona / rele / rele / subscription.py View on Github external
def __call__(self, message):
        run_middleware_hook("pre_process_message", self._subscription, message)
        start_time = time.time()

        try:
            data = json.loads(message.data.decode("utf-8"))
        except json.JSONDecodeError as e:
            message.ack()
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
                start_time,
                message,
            )
            run_middleware_hook("post_process_message")
            return

        try:
            res = self._subscription(data, **dict(message.attributes))
        except Exception as e:
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
                start_time,
                message,
            )
        else:
            message.ack()
            run_middleware_hook(
                "post_process_message_success", self._subscription, start_time, message,
github mercadona / rele / rele / subscription.py View on Github external
def __call__(self, message):
        run_middleware_hook("pre_process_message", self._subscription, message)
        start_time = time.time()

        try:
            data = json.loads(message.data.decode("utf-8"))
        except json.JSONDecodeError as e:
            message.ack()
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
                start_time,
                message,
            )
            run_middleware_hook("post_process_message")
            return

        try:
            res = self._subscription(data, **dict(message.attributes))
        except Exception as e:
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
github mercadona / rele / rele / client.py View on Github external
attrs["published_at"] = str(time.time())
        run_middleware_hook("pre_publish", topic, data, attrs)
        payload = json.dumps(data, cls=self._encoder).encode("utf-8")
        topic_path = self._client.topic_path(self._gc_project_id, topic)
        future = self._client.publish(topic_path, payload, **attrs)
        if not blocking:
            return future

        try:
            future.result(timeout=timeout or self._timeout)
        except TimeoutError as e:
            run_middleware_hook("post_publish_failure", topic, e, data)
            if raise_exception:
                raise e
        else:
            run_middleware_hook("post_publish", topic)

        return future
github mercadona / rele / rele / subscription.py View on Github external
def __call__(self, message):
        run_middleware_hook("pre_process_message", self._subscription, message)
        start_time = time.time()

        try:
            data = json.loads(message.data.decode("utf-8"))
        except json.JSONDecodeError as e:
            message.ack()
            run_middleware_hook(
                "post_process_message_failure",
                self._subscription,
                e,
                start_time,
                message,
            )
            run_middleware_hook("post_process_message")
            return