Files
3cloud-backend/app/celery_app.py
T
coryHawkvelt 4a3681c667 feat(cloudflare): add reconciliation worker and beat task
- Introduce CloudflareReconciliationWorker to reconcile Cloudflare
  tunnels/DNS with DB and clean up stale resources
- Add Celery task tasks.cloudflare_reconciliation and schedule it
  every 5 minutes via beat
- Provide standalone script to run the reconciliation manually
- Add optional scheduler helper for periodic runs

Also:
- Update tunnel lookup to not ignore tunnels in down status so
  cleanup can find and delete them

No breaking changes.
2025-10-27 04:16:11 +10:30

57 lines
1.9 KiB
Python

"""
celery_factory.py -- Re-export the canonical Celery instance.
This file used to create a *second* Celery app. Since `app/__init__.py`
now owns the one-and-only `celery_app`, we simply import and expose it
here so legacy imports (`from app.celery_factory import celery`) keep
working.
If you want per-project beat schedules, append them to `celery_app.conf`
after import.
"""
from logger import logger
from app import celery_app as celery # ← single source-of-truth
from app import app as flask_app # access to config & logger
# log = getLogger("xcloudify.celery_factory")
logger.info("Using existing Celery instance from app.__init__")
# ───────────────────────── Optional: add beat jobs ────────────────────
celery.conf.beat_schedule.update(
{
# "heartbeat-30s": {
# "task": "tasks.log_heartbeat",
# "schedule": 30.0,
# },
"reconcile_online_workers-30s": {
"task": "tasks.reconcile_online_workers",
"schedule": 30.0,
},
"retry-waiting-host-pods-10s": {
"task": "tasks.retry_waiting_host_pods",
"schedule": 10.0,
},
"cloudflare-reconciliation-5m": {
"task": "tasks.cloudflare_reconciliation",
"schedule": 300.0, # 5 minutes
}
# Add more periodic jobs here if desired
# "collect-system-metrics": {
# "task": "tasks.collect_system_metrics",
# "schedule": timedelta(minutes=1),
# },
}
)
# The export below keeps your old import paths valid:
__all__ = ["celery"]
import app.tasks.process_workload_request
import app.tasks.simple
import app.tasks.reconcile_online_workers
import app.tasks.container_lifecycle
import app.tasks.host_monitoring
import app.tasks.allocation_retry
import app.tasks.cloudflare_reconciliation_task