-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from backend-developers-ltd/worker-healthcheck
Make celery services restart if they stop doing tasks
- Loading branch information
Showing
9 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
# Check if the file does not exist | ||
if [[ ! -f "$WORKER_HEALTHCHECK_FILE_PATH" ]]; then | ||
# Create the parent directory, if necessary | ||
mkdir -p "$(dirname "$WORKER_HEALTHCHECK_FILE_PATH")" | ||
# Create the file | ||
touch "$WORKER_HEALTHCHECK_FILE_PATH" | ||
fi | ||
|
||
# Default timeout - 10 seconds | ||
WORKER_HEALTHCHECK_TIMEOUT=${WORKER_HEALTHCHECK_TIMEOUT:-10} | ||
|
||
# Check the file's modification time | ||
MOD_TIME=$(stat -c %Y "$WORKER_HEALTHCHECK_FILE_PATH") | ||
CURRENT_TIME=$(date +%s) | ||
|
||
if (( CURRENT_TIME - MOD_TIME > WORKER_HEALTHCHECK_TIMEOUT )); then | ||
# Liveness check failed: file not modified within $WORKER_HEALTHCHECK_TIMEOUT seconds | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import os | ||
|
||
import kombu | ||
|
||
# Copied from settings.py to not setup Django in a healthcheck | ||
REDIS_HOST = os.getenv("REDIS_HOST", default="redis") | ||
REDIS_PORT = os.getenv("REDIS_PORT", default="6379") | ||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", default=f"redis://{REDIS_HOST}:{REDIS_PORT}/0") | ||
|
||
with kombu.Connection(CELERY_BROKER_URL) as conn: | ||
conn.connect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.