Skip to main content

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:

  1. Embeds a FastAPI application inside your Celery worker
  2. Runs on port 9000 by default (configurable)
  3. 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)

Beat Health Check

celery-healthcheck also supports adding a liveness probe for celery beat.

It works by hooking Celery's beat_init signal and patching the tick() method on whichever scheduler instance beat actually constructs, so it works identically with the stock scheduler, django-celery-beat, redbeat, or any custom scheduler.

This method ensures that the liveness probe reflects whether beat is still actively scheduling tasks.

from celery import Celery
import celery_healthcheck

app = Celery('myapp')
app.config_from_object('myapp.celeryconfig')

celery_healthcheck.register(app)
celery -A myapp beat -l info

GET / (Beat)

Reports whether beat has ticked recently.

Response:

{
  "status": "ok",           // or "error"
  "last_tick_age": 4.2,     // seconds since the last tick
  "max_tick_age": 610.0     // staleness threshold currently in effect
}

Beat Configuration

  • healthcheck_beat_port: The port on which the beat health check server will listen (default: 9001)
  • healthcheck_beat_max_tick_age: Explicit override for the staleness threshold, in seconds. If unset, it's derived from the scheduler's own max_interval instead (see below).
  • healthcheck_beat_tick_age_multiplier: Multiplier applied to the scheduler's max_interval when deriving the default threshold (default: 2.0)

Azure Configuration

When configuring Azure health probes:

  1. Set the probe to use HTTP
  2. Point to port 9000
  3. Use the path "/"
  4. 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

Metadata

Release files for celery-healthcheck 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for celery-healthcheck 0.3.0
File Size Uploaded
celery_healthcheck-0.3.0.tar.gz 36.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for celery-healthcheck 0.3.0
File Interpreter ABI Platform
celery_healthcheck-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.9 kB

Release files / celery_healthcheck-0.3.0.tar.gz

Download URL celery_healthcheck-0.3.0.tar.gz
Size 36.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9c1f83eb40ec544331c44cee8bae5d1366765344ff9bb8bf06d470ef956b8d8e
BLAKE2b-256 checksum
How to use checksums
8abd50224c0e0f92bac9da319646f1b30e8f6f2695275df52767936d2a6bc51d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.6

Release files / celery_healthcheck-0.3.0-py3-none-any.whl

Download URL celery_healthcheck-0.3.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2eea09e77247f5ddeaf0a5850b2265541e057ede0c31e702a9ef0afccfea95eb
BLAKE2b-256 checksum
How to use checksums
53031ebe718f6f3982f895274067654ce60919825c05d55011ffe4dee3e3a842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page