Skip to content

Commit 8f2ae44

Browse files
committed
some improvements
1 parent 54e6178 commit 8f2ae44

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

services/director/src/simcore_service_director/registry_cache_task.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import logging
33

44
from fastapi import FastAPI
5-
from servicelib.utils import logged_gather
5+
from servicelib.logging_utils import log_context
6+
from servicelib.utils import limited_gather
67

78
from . import exceptions, registry_proxy
89
from .core.settings import ApplicationSettings, get_application_settings
@@ -15,28 +16,21 @@
1516
async def registry_caching_task(app: FastAPI) -> None:
1617
app_settings = get_application_settings(app)
1718
try:
19+
with log_context(_logger, logging.INFO, msg=f"{TASK_NAME}: starting"):
20+
assert hasattr(app.state, "registry_cache") # nosec
21+
assert isinstance(app.state.registry_cache, dict) # nosec
22+
app.state.registry_cache.clear()
1823

19-
_logger.info("%s: initializing cache...", TASK_NAME)
20-
assert hasattr(app.state, "registry_cache") # nosec
21-
assert isinstance(app.state.registry_cache, dict) # nosec
22-
app.state.registry_cache.clear()
2324
await registry_proxy.list_services(app, registry_proxy.ServiceType.ALL)
24-
_logger.info("%s: initialisation completed", TASK_NAME)
2525
while True:
2626
_logger.info("%s: waking up, refreshing cache...", TASK_NAME)
2727
try:
28-
keys = []
29-
refresh_tasks = []
30-
for key in app.state.registry_cache:
31-
path, method = key.split(":")
32-
_logger.debug("refresh %s:%s", method, path)
33-
refresh_tasks.append(
34-
registry_proxy.registry_request(
35-
app, path, method, no_cache=True
36-
)
37-
)
28+
refresh_tasks = [
29+
registry_proxy.registry_request(app, key.split(":"), no_cache=True)
30+
for key in app.state.registry_cache
31+
]
3832
keys = list(app.state.registry_cache.keys())
39-
results = await logged_gather(*refresh_tasks)
33+
results = await limited_gather(*refresh_tasks, log=_logger, limit=50)
4034

4135
for key, result in zip(keys, results, strict=False):
4236
app.state.registry_cache[key] = result

0 commit comments

Comments
 (0)