|
| 1 | +from datetime import timedelta |
| 2 | +from typing import Annotated |
| 3 | + |
| 4 | +from pydantic import Field |
| 5 | +from pydantic_settings import SettingsConfigDict |
| 6 | +from settings_library.rabbit import RabbitSettings |
| 7 | +from settings_library.redis import RedisSettings |
| 8 | + |
| 9 | +from .base import BaseCustomSettings |
| 10 | + |
| 11 | + |
| 12 | +class CelerySettings(BaseCustomSettings): |
| 13 | + CELERY_RABBIT_BROKER: Annotated[ |
| 14 | + RabbitSettings, Field(json_schema_extra={"auto_default_from_env": True}) |
| 15 | + ] |
| 16 | + CELERY_REDIS_RESULT_BACKEND: Annotated[ |
| 17 | + RedisSettings, Field(json_schema_extra={"auto_default_from_env": True}) |
| 18 | + ] |
| 19 | + CELERY_RESULT_EXPIRES: Annotated[ |
| 20 | + timedelta, |
| 21 | + Field( |
| 22 | + description="Time after which task results will be deleted (default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)." |
| 23 | + ), |
| 24 | + ] = timedelta(days=7) |
| 25 | + CELERY_RESULT_PERSISTENT: Annotated[ |
| 26 | + bool, |
| 27 | + Field( |
| 28 | + description="If set to True, result messages will be persistent (after a broker restart)." |
| 29 | + ), |
| 30 | + ] = True |
| 31 | + |
| 32 | + model_config = SettingsConfigDict( |
| 33 | + json_schema_extra={ |
| 34 | + "examples": [ |
| 35 | + { |
| 36 | + "CELERY_RABBIT_BROKER": { |
| 37 | + "RABBIT_USER": "guest", |
| 38 | + "RABBIT_SECURE": False, |
| 39 | + "RABBIT_PASSWORD": "guest", |
| 40 | + "RABBIT_HOST": "localhost", |
| 41 | + "RABBIT_PORT": 5672, |
| 42 | + }, |
| 43 | + "CELERY_REDIS_RESULT_BACKEND": { |
| 44 | + "REDIS_HOST": "localhost", |
| 45 | + "REDIS_PORT": 6379, |
| 46 | + }, |
| 47 | + "CELERY_RESULT_EXPIRES": timedelta(days=1), # type: ignore[dict-item] |
| 48 | + "CELERY_RESULT_PERSISTENT": True, |
| 49 | + } |
| 50 | + ], |
| 51 | + } |
| 52 | + ) |
0 commit comments