Internal
Public Access
Fix celery container health issues
- Fix import error in notifications/tasks.py (timezone.datetime -> datetime) - Add healthchecks to celery-worker and celery-beat containers - Add procps package to Dockerfile for pgrep command - Add email environment variables to celery containers The import error was causing celery workers to crash when loading tasks. Missing healthchecks prevented proper container health monitoring. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
9dd5d9c154
commit
e0ee377a20
@@ -28,6 +28,7 @@ FROM python:3.12-slim-bookworm
|
|||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
postgresql-client \
|
postgresql-client \
|
||||||
curl \
|
curl \
|
||||||
|
procps \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Create django user (non-root for security)
|
# Create django user (non-root for security)
|
||||||
|
|||||||
@@ -112,6 +112,12 @@ services:
|
|||||||
SECRET_KEY: ${SECRET_KEY}
|
SECRET_KEY: ${SECRET_KEY}
|
||||||
DATABASE_URL: postgresql://${DB_USER:-keepitgoing}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-keepitgoing}
|
DATABASE_URL: postgresql://${DB_USER:-keepitgoing}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-keepitgoing}
|
||||||
REDIS_URL: redis://redis:6379/0
|
REDIS_URL: redis://redis:6379/0
|
||||||
|
EMAIL_HOST: ${EMAIL_HOST:-}
|
||||||
|
EMAIL_PORT: ${EMAIL_PORT:-587}
|
||||||
|
EMAIL_HOST_USER: ${EMAIL_HOST_USER:-}
|
||||||
|
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD:-}
|
||||||
|
EMAIL_USE_TLS: ${EMAIL_USE_TLS:-True}
|
||||||
|
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:-noreply@localhost}
|
||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -120,6 +126,12 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
command: celery-worker
|
command: celery-worker
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "celery -A config inspect ping -d celery@$$HOSTNAME"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
|
|
||||||
# =================================================================
|
# =================================================================
|
||||||
# Celery Beat Service - Scheduled task scheduler
|
# Celery Beat Service - Scheduled task scheduler
|
||||||
@@ -135,6 +147,12 @@ services:
|
|||||||
SECRET_KEY: ${SECRET_KEY}
|
SECRET_KEY: ${SECRET_KEY}
|
||||||
DATABASE_URL: postgresql://${DB_USER:-keepitgoing}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-keepitgoing}
|
DATABASE_URL: postgresql://${DB_USER:-keepitgoing}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-keepitgoing}
|
||||||
REDIS_URL: redis://redis:6379/0
|
REDIS_URL: redis://redis:6379/0
|
||||||
|
EMAIL_HOST: ${EMAIL_HOST:-}
|
||||||
|
EMAIL_PORT: ${EMAIL_PORT:-587}
|
||||||
|
EMAIL_HOST_USER: ${EMAIL_HOST_USER:-}
|
||||||
|
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD:-}
|
||||||
|
EMAIL_USE_TLS: ${EMAIL_USE_TLS:-True}
|
||||||
|
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:-noreply@localhost}
|
||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -143,6 +161,12 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
command: celery-beat
|
command: celery-beat
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pgrep -f 'celery.*beat' || exit 1"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
# =================================================================
|
# =================================================================
|
||||||
# Named Volumes
|
# Named Volumes
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ def schedule_task_reminder(task_id):
|
|||||||
else:
|
else:
|
||||||
# Default to 9 AM on due date
|
# Default to 9 AM on due date
|
||||||
due_datetime = timezone.make_aware(
|
due_datetime = timezone.make_aware(
|
||||||
timezone.datetime.combine(task.due_date, timezone.datetime.min.time())
|
datetime.combine(task.due_date, datetime.min.time())
|
||||||
).replace(hour=9)
|
).replace(hour=9)
|
||||||
|
|
||||||
remind_at = due_datetime - timedelta(minutes=reminder_minutes)
|
remind_at = due_datetime - timedelta(minutes=reminder_minutes)
|
||||||
|
|||||||
Reference in New Issue
Block a user