import os
from celery import Celery
from celery.schedules import crontab

REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0")

celery_app = Celery(
    "backtestingmarket",
    broker=REDIS_URL,
    backend=REDIS_URL,
)

celery_app.conf.update(
    beat_schedule={
        "check-webhooks-every-5min": {
            "task": "webhook_task.check_and_fire_webhooks",
            "schedule": crontab(
                minute="0,5,10,15,20,25,30,35,40,45,50,55",
                hour="*",
                day_of_week="1-5",
            ),
            "options": {"queue": "webhooks_queue"},
        },
    },
)