Skip to main content

Embedded HTTP uptime checks for Celery worker and beat processes

Project description

celery-uptime

celery-uptime adds lightweight HTTP health and readiness endpoints to Celery workers and beat without changing the Celery command you already run.

from celery import Celery
from celery_uptime import monitor

app = Celery("my-service", broker="sqs://", backend="redis://redis:6379/0")

monitor(app)

Then keep your normal command:

celery -A my_service.celery_app worker --loglevel=info

The package starts an embedded Uvicorn server from Celery lifecycle signals. It starts on worker_ready for workers and beat_init for beat.

Installation

The base package only installs Celery, FastAPI, and Uvicorn. Install the extras matching the providers your Celery app already uses:

pip install "celery-uptime[redis,sqs]"

Available extras:

  • redis: Redis broker/backend and Redis Sentinel.
  • sqs: SQS broker.
  • kafka: Kafka broker through Kombu's Confluent Kafka transport.
  • sqlalchemy: SQLAlchemy/database result backend.
  • django: Django database/cache result backends.
  • mongodb: MongoDB result backend.
  • elasticsearch: Elasticsearch result backend.
  • cassandra: Cassandra result backend.
  • memcache: Memcached cache result backend.
  • all: all optional provider dependencies.

Missing provider dependencies do not crash the monitor. /ready returns a failing check with details such as missing_extra:mongodb.

Endpoints

  • GET /health: returns process/server liveness.
  • GET /ready: returns Celery process readiness plus broker/backend checks.

Example /ready response:

{
  "status": "ok",
  "service": "my-service-celery-worker",
  "process": "worker",
  "checks": {
    "celery_process": {"status": "ok", "detail": "ready"},
    "broker": {"status": "ok", "detail": "ok"},
    "backend": {"status": "ok", "detail": "ok"}
  }
}

Configuration

Environment variables:

  • CELERY_UPTIME_ENABLED=true
  • CELERY_UPTIME_HOST=0.0.0.0
  • CELERY_UPTIME_PORT=8090
  • CELERY_UPTIME_SERVICE=<celery app main>-celery-<worker|beat>
  • CELERY_UPTIME_LOG_LEVEL=warning
  • CELERY_UPTIME_CHECK_INTERVAL=30
  • CELERY_UPTIME_CHECK_TIMEOUT=5
  • CELERY_UPTIME_STALE_AFTER=90

Docker Compose example:

services:
  celery-worker:
    command: ["celery", "-A", "my_service.celery_app", "worker", "--loglevel=info"]
    environment:
      - CELERY_UPTIME_PORT=8090
    ports:
      - "49211:8090"
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8090/health', timeout=5).read()\" || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

If your image includes curl, the healthcheck can be shorter:

services:
  celery-worker:
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS --max-time 5 http://127.0.0.1:8090/health > /dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Use /health for Docker/container liveness. It does not run broker/backend checks and is the safer endpoint for long-running task workers. Use /ready from external monitoring systems such as Uptime Kuma when you want dependency visibility and alerting. Avoid wiring /ready failures directly to automatic worker restarts unless your task loss/retry behavior is intentionally designed for that.

External readiness check examples:

curl -fsS --max-time 5 http://127.0.0.1:8090/health
curl -fsS --max-time 5 http://127.0.0.1:8090/ready

/ready is served from a cache populated by a background probe loop, so HTTP requests do not block on broker/backend clients. Before the first probe it returns 503 with detail: "not_checked_yet". If the cached probe result is older than CELERY_UPTIME_STALE_AFTER, it returns 503 with detail: "stale".

Automatic Checks

monitor(app) automatically detects:

  • RabbitMQ/AMQP broker: amqp://, pyamqp://, librabbitmq://.
  • Redis broker/backend: redis://, rediss://.
  • Redis Sentinel broker/backend: sentinel:// with master_name.
  • SQS broker: sqs:// with broker_transport_options.
  • Kafka broker: kafka://, confluentkafka://.
  • SQLAlchemy/database backend: db+..., database+....
  • Django backend conventions: django-db, django-cache.
  • RPC backend: rpc://, checked through broker connectivity.
  • Memcached backend: cache+memcached://, cache+pymemcache://, cache+pylibmc://.
  • MongoDB backend: mongodb://, mongodb+srv://.
  • Elasticsearch backend: elasticsearch://.
  • Cassandra backend: cassandra://.

No result backend is valid Celery configuration. If result_backend is absent or disabled://, /ready reports the backend as healthy and non-required:

{"status": "ok", "detail": "disabled", "required": false}

Unsupported providers outside this classic set fail closed in /ready unless you replace them with explicit checks.

Explicit Checks

For unusual apps, pass explicit checks:

from celery_uptime import database_check, monitor, redis_check, sqs_check

monitor(
    app,
    checks=[
        sqs_check(
            "broker",
            endpoint_url="https://sqs.fr-par.scw.cloud",
            region="fr-par",
            queue_url="https://sqs.fr-par.scw.cloud/queue",
            access_key="...",
            secret_key="...",
        ),
        redis_check("backend", "redis://redis:6379/0"),
        database_check("reporting-db", "postgresql://user:password@db:5432/app"),
    ],
    include_auto_checks=False,
)

Provider checks are connection-only. They do not write/read/delete Celery result records or mutate broker/backend data.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celery_uptime-0.0.1.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celery_uptime-0.0.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file celery_uptime-0.0.1.tar.gz.

File metadata

  • Download URL: celery_uptime-0.0.1.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for celery_uptime-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9955768c6e1ff3220cf4862dd48b076d5a1cc0769f10d2a065474fd921540818
MD5 97044d1bbbf70cdd2676ee9a6c9cec1e
BLAKE2b-256 d106a9da42576ff377bc7350ef24dc49285dd07dd1c44cbc6c9988ddfffedc62

See more details on using hashes here.

File details

Details for the file celery_uptime-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: celery_uptime-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for celery_uptime-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cbdfb2a6999023eea12f45155338e304a5c9eac97683d90298c761c5037624b
MD5 5d05da2a26a3248c519a967a46c1b8ce
BLAKE2b-256 65a5c6aa82c16357b4b9d7af22ac7ac62aaabbb0cb4f7f6d493b3e16422a68ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page