-
Notifications
You must be signed in to change notification settings - Fork 6
/
celery-healthcheck
executable file
·53 lines (47 loc) · 2.03 KB
/
celery-healthcheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
INFO="[INFO] "
ERROR="[ERROR] "
echo "${INFO}Starting Celery Healthcheck"
# detect weaver version to adjust celery CLI parameter order accordingly to expected package dependency
weaver_version=$(weaver --version | cut -d ' ' -f 2)
celery_greater=$(python -c "
from distutils.version import LooseVersion; print(LooseVersion(\"${weaver_version}\") >= LooseVersion(\"4.15.0\"))
")
# retrieve the results with the appropriate parameter order in each case
if [[ "${celery_greater}" = "True" ]]; then
result=$(celery -A pyramid_celery.celery_app inspect registered --ini "${APP_CONFIG_DIR}/weaver.ini" --timeout 5)
else
result=$(celery inspect registered -A pyramid_celery.celery_app --ini "${APP_CONFIG_DIR}/weaver.ini" --timeout 5)
fi
if [[ -z "${result}" ]]; then
echo "${ERROR}Empty Celery response."
exit 1
fi
# should look like (minimally):
# [... weaver-logs ...]
# -> celery@<uuid>: OK
# * weaver.processes.execution.execute_process
# more tasks possible depending on Weaver version and enabled features
celery_status_index=$(echo "${result}" | grep --line-number -E '^-> celery' | cut -d ':' -f 1)
if [[ -z "${celery_status_index}" ]]; then
echo "${ERROR}Empty Celery status."
exit 1
fi
celery_status_tasks=$(($(echo "${result}" | wc -l) - celery_status_index))
celery_status_lines=$((celery_status_tasks + 1))
celery_status_result=$(echo "${result}" | tail -n ${celery_status_lines})
celery_status=$(echo "${celery_status_result}" | head -n 1)
celery_tasks=$(echo "${celery_status_result}" | tail -n ${celery_status_tasks})
echo "${INFO}Celery inspect results dump:"
echo "${celery_status_result}"
if [[ $(echo "${celery_status}" | grep -c "OK") -ne 1 ]]; then
echo "${ERROR}Celery inspect did not return expected 'OK' status."
exit 2
fi
# validate only the task that is always required
if [[ $(echo "${celery_tasks}" | grep -c "weaver.processes.execution.execute_process") -ne 1 ]]; then
echo "${ERROR}Celery inspect did not retrieve expected task."
exit 3
fi
echo "${INFO}Success. Celery Worker is ready."
exit 0