Skip to content

Commit 6ab33bd

Browse files
add healthcheck
1 parent 920a912 commit 6ab33bd

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

services/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ services:
11781178
S3_ENDPOINT: ${S3_ENDPOINT}
11791179
S3_REGION: ${S3_REGION}
11801180
S3_SECRET_KEY: ${S3_SECRET_KEY}
1181-
STORAGE_WORKER_MODE: "False"
1181+
STORAGE_WORKER_MODE: 0
11821182
STORAGE_LOGLEVEL: ${STORAGE_LOGLEVEL}
11831183
STORAGE_MONITORING_ENABLED: 1
11841184
STORAGE_PROFILING: ${STORAGE_PROFILING}
@@ -1193,7 +1193,7 @@ services:
11931193
storage-worker:
11941194
image: ${DOCKER_REGISTRY:-itisfoundation}/storage:${DOCKER_IMAGE_TAG:-latest}
11951195
init: true
1196-
hostname: "sto-{{.Node.Hostname}}-{{.Task.Slot}}"
1196+
hostname: "stow-{{.Node.Hostname}}-{{.Task.Slot}}"
11971197
environment:
11981198
BF_API_KEY: ${BF_API_KEY}
11991199
BF_API_SECRET: ${BF_API_SECRET}
@@ -1221,7 +1221,7 @@ services:
12211221
S3_ENDPOINT: ${S3_ENDPOINT}
12221222
S3_REGION: ${S3_REGION}
12231223
S3_SECRET_KEY: ${S3_SECRET_KEY}
1224-
STORAGE_WORKER_MODE: "True"
1224+
STORAGE_WORKER_MODE: 1
12251225
STORAGE_LOGLEVEL: ${STORAGE_LOGLEVEL}
12261226
STORAGE_MONITORING_ENABLED: 1
12271227
STORAGE_PROFILING: ${STORAGE_PROFILING}

services/storage/docker/boot.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ if [ "${SC_BOOT_MODE}" = "debug" ]; then
5656
--log-level \"${SERVER_LOG_LEVEL}\"
5757
"
5858
else
59-
if [ "${STORAGE_WORKER_MODE}" = "True" ]; then
59+
if [ "${STORAGE_WORKER_MODE}" = "1" ]; then
6060
exec celery \
61-
--app=simcore_service_storage.modules.celery.worker_main \
61+
--app=simcore_service_storage.modules.celery.worker_main:app \
6262
worker --pool=threads \
63-
--loglevel="${SERVER_LOG_LEVEL}"
63+
--loglevel="${SERVER_LOG_LEVEL}" \
64+
--hostname="${HOSTNAME}"
6465
else
6566
exec uvicorn simcore_service_storage.main:app \
6667
--host 0.0.0.0 \

services/storage/docker/healthcheck.py

100644100755
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,50 @@
2020

2121

2222
import os
23+
import subprocess
2324
import sys
2425
from urllib.request import urlopen
2526

27+
from simcore_service_storage.main import ApplicationSettings
28+
2629
SUCCESS, UNHEALTHY = 0, 1
2730

2831
# Disabled if boots with debugger
29-
ok = os.environ.get("SC_BOOT_MODE", "").lower() == "debug"
32+
ok = os.getenv("SC_BOOT_MODE", "").lower() == "debug"
3033

3134
# Queries host
3235
# pylint: disable=consider-using-with
36+
app_settings = ApplicationSettings.create_from_envs()
37+
38+
broker_url = app_settings.STORAGE_CELERY_BROKER.dsn
39+
40+
41+
def _is_celery_worker_healthy():
42+
try:
43+
result = subprocess.run(
44+
[
45+
"celery",
46+
"-b",
47+
broker_url,
48+
"inspect",
49+
"ping",
50+
"-d",
51+
"celery@" + os.getenv("HOSTNAME", ""),
52+
],
53+
capture_output=True,
54+
text=True,
55+
check=True,
56+
)
57+
return "pong" in result.stdout
58+
except subprocess.CalledProcessError:
59+
return False
60+
61+
62+
print(_is_celery_worker_healthy())
63+
3364
ok = (
3465
ok
66+
or (bool(os.environ.get("STORAGE_WORKER_MODE", "") and _is_celery_worker_healthy()))
3567
or urlopen(
3668
"{host}{baseurl}".format(
3769
host=sys.argv[1], baseurl=os.environ.get("SIMCORE_NODE_BASEPATH", "")

services/storage/src/simcore_service_storage/core/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
106106
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of _logger message patterns that should be filtered out.",
107107
)
108108

109-
STORAGE_WORKER_MODE: bool | None = False
109+
STORAGE_WORKER_MODE: Annotated[
110+
bool | None, Field(description="If True, run as a worker")
111+
] = False
112+
STORAGE_CELERY_BROKER: RabbitSettings | None = Field(
113+
json_schema_extra={"auto_default_from_env": True}
114+
)
110115

111116
@field_validator("LOG_LEVEL", mode="before")
112117
@classmethod

0 commit comments

Comments
 (0)