-
Notifications
You must be signed in to change notification settings - Fork 0
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 #74 from maykinmedia/feature/get-test-env-working
Get test env working
- Loading branch information
Showing
10 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Check the health of a Celery worker. | ||
# | ||
# The worker process writes and periodically touches a number of files that indicate it | ||
# is available and still healthy. If the worker becomes unhealthy for any reason, the | ||
# timestamp of when the heartbeat file was last touched will not update and the delta | ||
# becomes too big, allowing (container) orchestration to terminate and restart the | ||
# worker process. | ||
# | ||
# Example usage with Kubernetes, as a liveness probe: | ||
# | ||
# .. code-block:: yaml | ||
# | ||
# livenessProbe: | ||
# exec: | ||
# command: | ||
# - python | ||
# - /app/bin/check_celery_worker_liveness.py | ||
# initialDelaySeconds: 10 | ||
# periodSeconds: 30 # must be smaller than `MAX_WORKER_LIVENESS_DELTA` | ||
# | ||
# Reference: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command | ||
# | ||
# Supported environment variables: | ||
# | ||
# * ``MAX_WORKER_LIVENESS_DELTA``: maximum delta between heartbeats before reporting | ||
# failure, in seconds. Defaults to 60 (one minute). | ||
|
||
|
||
import os | ||
import sys | ||
import time | ||
from pathlib import Path | ||
|
||
HEARTBEAT_FILE = Path(__file__).parent.parent / "tmp" / "celery_worker_heartbeat" | ||
READINESS_FILE = Path(__file__).parent.parent / "tmp" / "celery_worker_ready" | ||
MAX_WORKER_LIVENESS_DELTA = int(os.getenv("MAX_WORKER_LIVENESS_DELTA", 60)) # seconds | ||
|
||
|
||
# check if worker is ready | ||
if not READINESS_FILE.is_file(): | ||
print("Celery worker not ready.") | ||
sys.exit(1) | ||
|
||
# check if worker is live | ||
if not HEARTBEAT_FILE.is_file(): | ||
print("Celery worker heartbeat not found.") | ||
sys.exit(1) | ||
|
||
# check if worker heartbeat satisfies constraint | ||
stats = HEARTBEAT_FILE.stat() | ||
worker_timestamp = stats.st_mtime | ||
current_timestamp = time.time() | ||
time_diff = current_timestamp - worker_timestamp | ||
|
||
if time_diff > MAX_WORKER_LIVENESS_DELTA: | ||
print("Celery worker heartbeat: interval exceeds constraint (60s).") | ||
sys.exit(1) | ||
|
||
print("Celery worker heartbeat found: OK.") | ||
sys.exit(0) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REACT_APP_API_URL=http://localhost:8080 | ||
REACT_APP_API_PATH=/api/v1 |
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,2 @@ | ||
REACT_APP_API_URL=REACT_APP_API_URL_PLACEHOLDER | ||
REACT_APP_API_PATH=REACT_APP_API_PATH_PLACEHOLDER |
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,9 @@ | ||
#!/bin/bash | ||
|
||
set -eux -o pipefail | ||
|
||
for file in /app/static/js/*.js; | ||
do | ||
sed -i 's|REACT_APP_API_URL_PLACEHOLDER|'${REACT_APP_API_URL}'|g' $file | ||
sed -i 's|REACT_APP_API_PATH_PLACEHOLDER|'${REACT_APP_API_PATH}'|g' $file | ||
done |
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