Skip to content

Commit

Permalink
Squash #2041 - Update Health Check to search for PID under dd-trace
Browse files Browse the repository at this point in the history
  • Loading branch information
MackHalliday committed Nov 21, 2024
1 parent 895a7c9 commit 2f63640
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 12 additions & 1 deletion cd/application-deployment/dev/vaec-celery-task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,18 @@
"sh",
"-c",
"/app/scripts/run_celery.sh"
]
],
"healthCheck": {
"command": [
"CMD",
"sh",
"-c",
"./scripts/check_celery.sh"
],
"interval": 30,
"retries": 5,
"timeout": 10
}
},
{
"name": "datadog-agent",
Expand Down
19 changes: 12 additions & 7 deletions scripts/check_celery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
set -e

function get_celery_pids {
# get the PIDs of the process whose parent is the main celery process, saved in celery.pid
# print only pid and their command, get the ones with "celery" in their name
# and keep only these PIDs
# First, get the PID from the celery.pid file
MAIN_PID=$(cat /tmp/celery.pid)

# Check if the main process is ddtrace-run or Celery directly
if pstree -p ${MAIN_PID} | grep -q 'ddtrace'; then
# If ddtrace-run is present, navigate to the child process
APP_PIDS=$(pstree -p ${MAIN_PID} | sed 's/.*-ddtrace(\([0-9]*\)).*-celery(\([0-9]*\)).*/\2/')
else
# If no ddtrace-run, assume the main process is Celery
APP_PIDS=$(pstree -p ${MAIN_PID} | sed 's/.*-celery(\([0-9]*\)).*/\1/')
fi

set +o pipefail # so grep returning no matches does not premature fail pipe
APP_PIDS=$(pstree -p `cat /tmp/celery.pid` | sed 's/\(.*\)-celery(\(\d*\))/\2/')
echo "Here are the APP_PIDS: ${APP_PIDS}"
set -o pipefail # pipefail should be set everywhere else
}

function ensure_celery_is_running {
Expand All @@ -20,7 +25,7 @@ function ensure_celery_is_running {
fi

for APP_PID in ${APP_PIDS}; do
kill -0 ${APP_PID} 2&>/dev/null || return 1
kill -0 ${APP_PID} 2>/dev/null || return 1
done
}

Expand Down

0 comments on commit 2f63640

Please sign in to comment.