Skip to content

Commit 31b06bd

Browse files
fix: docker scripts
1 parent 0ba8ce4 commit 31b06bd

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

services/notifications/docker/boot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ APP_LOG_LEVEL=${LOGLEVEL:-${LOG_LEVEL:-${LOGLEVEL:-INFO}}}
4747
SERVER_LOG_LEVEL=$(echo "${APP_LOG_LEVEL}" | tr '[:upper:]' '[:lower:]')
4848
echo "$INFO" "Log-level app/server: $APP_LOG_LEVEL/$SERVER_LOG_LEVEL"
4949

50-
if [ "${NOTIFICATIONS_WORKER_MODE}" = "true" ]; then
50+
if [ "${NOTIFICATIONS_WORKER_MODE:-}" = "true" ]; then
5151
if [ "${SC_BOOT_MODE}" = "debug" ]; then
5252
exec watchmedo auto-restart \
5353
--directory /devel/packages \

services/notifications/docker/healthcheck.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,50 @@
1616
- SEE https://blog.sixeyed.com/docker-healthchecks-why-not-to-use-curl-or-iwr/
1717
"""
1818
import os
19+
import subprocess
1920
import sys
2021
from urllib.request import urlopen
2122

23+
from simcore_service_notifications.core.application import ApplicationSettings
24+
2225
SUCCESS, UNHEALTHY = 0, 1
2326

24-
# Disabled if boots with debugger (e.g. debug, pdb-debug, debug-ptvsd, debugpy, etc)
25-
ok = "debug" in os.environ.get("SC_BOOT_MODE", "").lower()
27+
# Disabled if boots with debugger
28+
ok = os.getenv("SC_BOOT_MODE", "").lower() == "debug"
2629

2730
# Queries host
2831
# pylint: disable=consider-using-with
32+
33+
app_settings = ApplicationSettings.create_from_envs()
34+
35+
36+
def _is_celery_worker_healthy():
37+
assert app_settings.NOTIFICATIONS_CELERY
38+
broker_url = app_settings.NOTIFICATIONS_CELERY.CELERY_RABBIT_BROKER.dsn
39+
40+
try:
41+
result = subprocess.run(
42+
[
43+
"celery",
44+
"--broker",
45+
broker_url,
46+
"inspect",
47+
"ping",
48+
"--destination",
49+
"celery@" + os.getenv("NOTIFICATIONS_WORKER_NAME", "worker"),
50+
],
51+
capture_output=True,
52+
text=True,
53+
check=True,
54+
)
55+
return "pong" in result.stdout
56+
except subprocess.CalledProcessError:
57+
return False
58+
59+
2960
ok = (
3061
ok
62+
or (app_settings.NOTIFICATIONS_WORKER_MODE and _is_celery_worker_healthy())
3163
or urlopen(
3264
"{host}{baseurl}".format(
3365
host=sys.argv[1], baseurl=os.environ.get("SIMCORE_NODE_BASEPATH", "")

0 commit comments

Comments
 (0)