Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add liveness probe for celery workers #766

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions charts/airflow/templates/worker/worker-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,44 @@ spec:
time.sleep(10)
active_tasks = i.active()[local_celery_host]
{{- end }}
{{- if .Values.workers.livenessProbe.enabled }}
livenessProbe:
initialDelaySeconds: {{ .Values.workers.livenessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.workers.livenessProbe.timeoutSeconds }}
failureThreshold: {{ .Values.workers.livenessProbe.failureThreshold }}
periodSeconds: {{ .Values.workers.livenessProbe.periodSeconds }}
exec:
command:
{{- include "airflow.command" . | indent 16 }}
- "python"
- "-Wignore"
- "-c"
- |
import os
import sys
import subprocess
from celery import Celery
from celery.app.control import Inspect
from typing import List
def run_command(cmd: List[str]) -> str:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output, error = process.communicate()
if error is not None:
raise Exception(error)
else:
return output.decode(encoding="utf-8")
broker_url = run_command(["bash", "-c", "eval $AIRFLOW__CELERY__BROKER_URL_CMD"])
local_celery_host = f"celery@{os.environ['HOSTNAME']}"
app = Celery(broker=broker_url)
# ping the local celery worker to see if it's ok
i = Inspect(app=app, destination=[local_celery_host], timeout=5.0)
ping_responses = i.ping()
if local_celery_host not in ping_responses:
sys.exit(f"celery worker '{local_celery_host}' did not respond to ping")
{{- end }}
ports:
- name: wlog
containerPort: 8793
Expand Down
9 changes: 9 additions & 0 deletions charts/airflow/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,15 @@ workers:
##
intervalSeconds: 900

## configs for the worker Pods' liveness probe
##
livenessProbe:
enabled: true
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 60
failureThreshold: 5

## extra pip packages to install in the worker Pod
##
## ____ EXAMPLE _______________
Expand Down
Loading