-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rabbitmq/only listens to logs if needed (#4180)
- Loading branch information
Showing
15 changed files
with
238 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
services/web/server/src/simcore_service_webserver/notifications/_constants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from typing import Final | ||
|
||
APP_RABBITMQ_CONSUMERS_KEY: Final[str] = f"{__name__}.rabbit_consumers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
services/web/server/src/simcore_service_webserver/notifications/project_logs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from aiohttp import web | ||
from models_library.projects import ProjectID | ||
from models_library.rabbitmq_messages import LoggerRabbitMessage | ||
from servicelib.rabbitmq import RabbitMQClient | ||
|
||
from ..rabbitmq import get_rabbitmq_client | ||
from ._constants import APP_RABBITMQ_CONSUMERS_KEY | ||
|
||
|
||
def _get_queue_name_from_exchange_name(app: web.Application, exchange_name: str) -> str: | ||
exchange_to_queues = app[APP_RABBITMQ_CONSUMERS_KEY] | ||
queue_name = exchange_to_queues[exchange_name] | ||
return queue_name | ||
|
||
|
||
async def subscribe(app: web.Application, project_id: ProjectID) -> None: | ||
rabbit_client: RabbitMQClient = get_rabbitmq_client(app) | ||
exchange_name = LoggerRabbitMessage.get_channel_name() | ||
queue_name = _get_queue_name_from_exchange_name(app, exchange_name) | ||
await rabbit_client.add_topics( | ||
exchange_name, queue_name, topics=[f"{project_id}.*"] | ||
) | ||
|
||
|
||
async def unsubscribe(app: web.Application, project_id: ProjectID) -> None: | ||
rabbit_client: RabbitMQClient = get_rabbitmq_client(app) | ||
exchange_name = LoggerRabbitMessage.get_channel_name() | ||
queue_name = _get_queue_name_from_exchange_name(app, exchange_name) | ||
await rabbit_client.remove_topics( | ||
exchange_name, queue_name, topics=[f"{project_id}.*"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.