diff --git a/.gitignore b/.gitignore index a16fc91..e56e9a2 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ vite.config.ts.* *.sln *.sw? .history +celerybeat-schedule.db \ No newline at end of file diff --git a/README.md b/README.md index 6462291..06ddc8f 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,46 @@ node 版本v22.17.0 python manage.py runserver ``` + +## (可选)Django 项目中启动 Celery 的标准方法如下: +### Celery 任务队列与监控 +### 启动 Celery Worker +![Celery 启动界面](images/celery.png) + +```bash +celery -A backend worker -l info +``` + +### 启动 Celery Beat(如有定时任务) +定时任务配置在 `backend/backend/settings.py` 的 `CELERY_BEAT_SCHEDULE`。 +```python +CELERY_BEAT_SCHEDULE = { + 'every-1-minutes': { + 'task': 'system.tasks.sync_temu_order', # 任务路径 + 'schedule': 60, # 每1分钟执行一次 + }, +} +``` +```bash +celery -A backend beat -l info +``` + +### 启动 Flower 监控 + +```bash +celery -A backend flower --port=5555 --basic_auth=admin:admin123 +``` + +- `--port=5555`:指定 Flower 的访问端口(可自定义) +- `--basic_auth=用户名:密码`:设置访问 Flower 的账号密码(如 admin:admin123) + +启动后,浏览器访问 [http://localhost:5555](http://localhost:5555) ,输入账号密码即可进入 Celery 任务监控界面。 + +![Celery 监控界面](images/flower.png) + +--- + + ## 前端启动(以 web-antd 为例) > 说明:web-ele 目前暂不支持,待 InputPassword 等组件开发完毕后再兼容。 diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 5f3e254..eb0bd92 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -178,12 +178,12 @@ CELERY_RESULT_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT = ['json'] CELERY_BEAT_SCHEDULE = { - 'every-15-minutes': { - 'task': 'system.tasks.add', # 任务路径 - 'schedule': 900.0, # 每15分钟执行一次 + 'every-1-minutes': { + 'task': 'system.tasks.sync_temu_order', # 任务路径 + 'schedule': 60, # 每1分钟执行一次 }, } - +# celery 配置结束 if os.path.exists(os.path.join(BASE_DIR, 'backend/local_settings.py')): from backend.local_settings import * \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index 6ac4be8..eb23aaa 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -10,4 +10,5 @@ requests==2.32.3 celery==5.5.3 redis==6.2.0 eventlet==0.40.0 -goofish_api==0.0.6 \ No newline at end of file +goofish_api==0.0.6 +flower==2.0.1 \ No newline at end of file diff --git a/images/celery.png b/images/celery.png new file mode 100644 index 0000000..62f52fc Binary files /dev/null and b/images/celery.png differ diff --git a/images/flower.png b/images/flower.png new file mode 100644 index 0000000..a130b6b Binary files /dev/null and b/images/flower.png differ