from datetime import timedelta

from evibes.settings.base import REDIS_PASSWORD, TIME_ZONE

CELERY_ENABLE_UTC = False
CELERY_TIMEZONE = TIME_ZONE

CELERY_BROKER_URL = f"redis://:{REDIS_PASSWORD}@redis:6379/0"

CELERY_BROKER_HEARTBEAT = 10
CELERY_BROKER_HEARTBEAT_CHECKRATE = 2

CELERY_BROKER_POOL_LIMIT = 10
CELERY_BROKER_TRANSPORT_OPTIONS = {
    "visibility_timeout": 3600,
    "retry_policy": {"interval_start": 0.1, "interval_step": 0.2, "max_retries": 5},
    "socket_keepalive": True,
    "socket_timeout": 30,
    "socket_connect_timeout": 30,
    "retry_on_timeout": True,
}

CELERY_RESULT_BACKEND = CELERY_BROKER_URL

CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers.DatabaseScheduler"

CELERY_BEAT_SCHEDULE = {
    "update_products_task": {
        "task": "core.tasks.update_products_task",
        "schedule": timedelta(minutes=60),
        "options": {"queue": "stock_updater"},
    },
    "update_orderproducts_task": {
        "task": "core.tasks.update_orderproducts_task",
        "schedule": timedelta(minutes=1),
        "options": {"queue": "default"},
    },
    "set_default_caches_task": {
        "task": "core.tasks.set_default_caches_task",
        "schedule": timedelta(hours=4),
        "options": {"queue": "default"},
    },
    "remove_stale_product_images": {
        "task": "core.tasks.remove_stale_product_images",
        "schedule": timedelta(days=1),
        "options": {"queue": "default"},
    },
    "process_promotions": {
        "task": "core.tasks.process_promotions",
        "schedule": timedelta(hours=2),
        "options": {"queue": "default"},
    },
}
