File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
services/api-server/docker Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1818"""
1919
2020import os
21+ import subprocess
2122import sys
2223from urllib .request import urlopen
2324
25+ from simcore_service_api_server .core .settings import ApplicationSettings
26+
2427SUCCESS , UNHEALTHY = 0 , 1
2528
2629# Disabled if boots with debugger
2730ok = os .environ .get ("SC_BOOT_MODE" , "" ).lower () == "debug"
2831
32+ app_settings = ApplicationSettings .create_from_envs ()
33+
34+
35+ def _is_celery_worker_healthy ():
36+ assert app_settings .API_SERVER_CELERY
37+ broker_url = app_settings .API_SERVER_CELERY .CELERY_RABBIT_BROKER .dsn
38+
39+ try :
40+ result = subprocess .run (
41+ [
42+ "celery" ,
43+ "--broker" ,
44+ broker_url ,
45+ "inspect" ,
46+ "ping" ,
47+ "--destination" ,
48+ "celery@" + os .getenv ("API_SERVER_WORKER_NAME" , "worker" ),
49+ ],
50+ capture_output = True ,
51+ text = True ,
52+ check = True ,
53+ )
54+ return "pong" in result .stdout
55+ except subprocess .CalledProcessError :
56+ return False
57+
58+
2959# Queries host
3060# pylint: disable=consider-using-with
3161ok = (
3262 ok
63+ or (app_settings .API_SERVER_WORKER_MODE and _is_celery_worker_healthy ())
3364 or urlopen (
3465 "{host}{baseurl}" .format (
3566 host = sys .argv [1 ], baseurl = os .environ .get ("SIMCORE_NODE_BASEPATH" , "" )
You can’t perform that action at this time.
0 commit comments