mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
Add support for celery dynamic tasks (#715)
* Add support for celery dynamic tasks * Update the celery conf * Update the celery task tables name * Refactor the celery task-related interfaces * Optimize auto-discovery tasks * Remove redundant config * Refine the business codes * Optimize crontab validation returns * Update dependencies in pyproject toml * Fix some bugs * Update dependencies * Update the version to 1.7.0 * Fix update and delete event
This commit is contained in:
+1
-24
@@ -3,7 +3,6 @@
|
||||
from functools import lru_cache
|
||||
from typing import Any, Literal
|
||||
|
||||
from celery.schedules import crontab
|
||||
from pydantic import model_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
@@ -200,7 +199,6 @@ class Settings(BaseSettings):
|
||||
# App Task
|
||||
# .env Redis
|
||||
CELERY_BROKER_REDIS_DATABASE: int
|
||||
CELERY_BACKEND_REDIS_DATABASE: int
|
||||
|
||||
# .env RabbitMQ
|
||||
# docker run -d --hostname fba-mq --name fba-mq -p 5672:5672 -p 15672:15672 rabbitmq:latest
|
||||
@@ -211,30 +209,9 @@ class Settings(BaseSettings):
|
||||
|
||||
# 基础配置
|
||||
CELERY_BROKER: Literal['rabbitmq', 'redis'] = 'redis'
|
||||
CELERY_BACKEND_REDIS_PREFIX: str = 'fba:celery:'
|
||||
CELERY_BACKEND_REDIS_TIMEOUT: int = 5
|
||||
CELERY_TASK_PACKAGES: list[str] = [
|
||||
'app.task.celery_task',
|
||||
'app.task.celery_task.db_log',
|
||||
]
|
||||
CELERY_REDIS_PREFIX: str = 'fba:celery'
|
||||
CELERY_TASK_MAX_RETRIES: int = 5
|
||||
|
||||
# 定时任务配置
|
||||
CELERY_SCHEDULE: dict[str, dict[str, Any]] = {
|
||||
'exec-every-10-seconds': {
|
||||
'task': 'task_demo_async',
|
||||
'schedule': 10,
|
||||
},
|
||||
'exec-every-sunday': {
|
||||
'task': 'delete_db_opera_log',
|
||||
'schedule': crontab('0', '0', day_of_week='6'),
|
||||
},
|
||||
'exec-every-15-of-month': {
|
||||
'task': 'delete_db_login_log',
|
||||
'schedule': crontab('0', '0', day_of_month='15'),
|
||||
},
|
||||
}
|
||||
|
||||
# Plugin Code Generator
|
||||
CODE_GENERATOR_DOWNLOAD_ZIP_FILENAME: str = 'fba_generator'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user