添加celery启动文档

This commit is contained in:
xie7654
2025-07-03 19:50:08 +08:00
parent 232ed06008
commit 257c3dab0e
6 changed files with 47 additions and 5 deletions

1
.gitignore vendored
View File

@@ -68,3 +68,4 @@ vite.config.ts.*
*.sln
*.sw?
.history
celerybeat-schedule.db

View File

@@ -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 等组件开发完毕后再兼容。

View File

@@ -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 *

View File

@@ -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
goofish_api==0.0.6
flower==2.0.1

BIN
images/celery.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

BIN
images/flower.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB