Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 removing unsubscribe from rabbitmq + ♻️ comp resource tracking id change #4687

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ async def on_startup() -> None:
)

async def on_shutdown() -> None:
if (
app.state.rabbitmq_client
and not app.state.resource_tracker_rabbitmq_consumer
):
if app.state.rabbitmq_client:
await app.state.rabbitmq_client.close()

app.add_event_handler("startup", on_startup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ async def _subscribe_to_rabbitmq(app) -> str:
return subscribed_queue


async def _unsubscribe_from_rabbitmq(app) -> None:
with log_context(
_logger, logging.INFO, msg="Unsubscribing from rabbitmq channels"
), log_catch(_logger, reraise=False):
rabbit_client: RabbitMQClient = get_rabbitmq_client(app)
await rabbit_client.unsubscribe(app.state.resource_tracker_rabbitmq_consumer)


def on_app_startup(app: FastAPI) -> Callable[[], Awaitable[None]]:
async def _startup() -> None:
with log_context(
Expand All @@ -53,11 +45,12 @@ async def _startup() -> None:
return _startup


def on_app_shutdown(app: FastAPI) -> Callable[[], Awaitable[None]]:
def on_app_shutdown(
app: FastAPI, # pylint: disable=unused-argument
) -> Callable[[], Awaitable[None]]:
async def _stop() -> None:
if app.state.resource_tracker_rabbitmq_consumer:
await _unsubscribe_from_rabbitmq(app)
await app.state.rabbitmq_client.close()
# NOTE: We want to have persistent queue, therefore we will not unsubscribe
return None

return _stop

Expand Down