A lightweight HTTP health check server for Celery workers, designed to work with cloud platforms that only support TCP-based health probes
Project description
Celery Healthcheck
A lightweight HTTP health check server for Celery workers, designed to work with cloud platforms like Azure that only support TCP-based health probes.
Problem
When deploying Celery workers to cloud platforms like Azure, you need a way to verify the worker's health. However, Azure doesn't allow command execution for health checks and only supports TCP-based probes. This makes it challenging to properly monitor Celery workers.
Solution
celery-healthcheck spins up a small FastAPI server within each Celery worker that exposes an HTTP endpoint to check the worker's health status. This allows cloud platforms to perform health checks via HTTP requests rather than command execution.
Importantly, the ping-based healthcheck reports whether the worker is connected to the broker and responsive. However, it does not guarantee that the worker is processing tasks successfully nor does it indicate a problem with the Celery worker itself, as the ping can fail for reasons like the broker being unavailable. It is not recommended to autoheal the Celery worker based on the healthcheck due to the noise inherent in this signal.
Installation
pip install celery-healthcheck
Usage
Add the health check server to your Celery application:
from celery import Celery
import celery_healthcheck
app = Celery('myapp')
app.config_from_object('myapp.celeryconfig')
# Register the health check server
celery_healthcheck.register(app)
Now start your worker as usual
celery -A myapp worker -l info
How It Works
The health check server:
- Embeds a FastAPI application inside your Celery worker
- Runs on port 9000 by default (configurable)
- Exposes an HTTP endpoint (
GET /) that:- Uses Celery's inspect API to ping the current worker only
- Returns a JSON response with status and result
API Endpoints
GET /
Pings the Celery worker and returns its status.
Response:
{
"status": "ok", // or "error" if worker doesn't respond
"result": { ... } // Raw response from Celery's ping command
}
Configuration
The health check app can be configured via the main celery app it is registered on.
healthcheck_port: The port on which the health check server will listen (default: 9000)healthcheck_ping_timeout: The timeout for the ping command to the worker (default: 2.0 seconds)
Azure Configuration
When configuring Azure health probes:
- Set the probe to use HTTP
- Point to port 9000
- Use the path "/"
- A 200 OK response indicates the worker is healthy
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development tasks
Run tests
uv run pytest
Format
uvx ruff format
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file celery_healthcheck-0.2.0.tar.gz.
File metadata
- Download URL: celery_healthcheck-0.2.0.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
126604cfcefb6e8286415f8255ae752b7b426ccc6e0e90caf4a190716b6950a5
|
|
| MD5 |
d3b216a3a9a4ed769690a868366f6fc0
|
|
| BLAKE2b-256 |
da145d09ddf6bb35be85aa2064fd59ec7cb1f4aef3cea06c5c2025f60822c7b6
|
File details
Details for the file celery_healthcheck-0.2.0-py3-none-any.whl.
File metadata
- Download URL: celery_healthcheck-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7464e5ac5798d31cf854da15559350134e682c9149e907e9740ce8349c9f21fa
|
|
| MD5 |
b97ddc14f778d487af48c1f3fa2c2639
|
|
| BLAKE2b-256 |
7ae1236c0dc37fa0077e9af821ab72456bbcb55dee825661cd4c124f43e68050
|