"""Celery application.

A minimal app for Phase 0/1 — async ingestion, scheduled runs, and beat
schedules are wired up in later phases. Broker/backend come from ``REDIS_URL``.
"""

from __future__ import annotations

from celery import Celery

from legate.config import get_settings

settings = get_settings()

celery_app = Celery(
    "legate",
    broker=settings.redis_url,
    backend=settings.redis_url,
)
celery_app.conf.update(
    task_serializer="json",
    accept_content=["json"],
    result_serializer="json",
    timezone="UTC",
    enable_utc=True,
    beat_schedule={
        "workflow-scheduler": {
            "task": "legate.workflow.scheduler",
            "schedule": 60.0,  # check for due scheduled workflows every minute
        },
    },
)


@celery_app.task(name="legate.ping")
def ping() -> str:
    """Trivial liveness task used to verify the worker is processing jobs."""
    return "pong"
