0 3 * * *system_config 表-- 修改为每天北京时间 15:00(UTC 07:00)
UPDATE system_config
SET config_value = '0 7 * * *', updated_by = 'your_name'
WHERE config_key = 'cron_schedule';
-- 查看当前配置
SELECT config_value FROM system_config WHERE config_key = 'cron_schedule';
from db import update_system_config
# 修改为每天北京时间 09:00(UTC 01:00)
update_system_config('cron_schedule', '0 1 * * *', updated_by='admin')
| 说明 | Cron表达式 | UTC时间 | 北京时间 |
|---|---|---|---|
| 每天上午9点 | 0 1 * * * |
01:00 | 09:00 |
| 每天上午11点 | 0 3 * * * |
03:00 | 11:00 ✅ (当前) |
| 每天下午3点 | 0 7 * * * |
07:00 | 15:00 |
| 每天晚上9点 | 0 13 * * * |
13:00 | 21:00 |
| 每12小时 | 0 */12 * * * |
00:00, 12:00 | 08:00, 20:00 |
URL: POST http://localhost:8080/trigger
说明: 手动触发一次决策流程,不影响定时任务
# 本地触发
curl -X POST http://localhost:8080/trigger
# 远程触发(如果部署在Kubernetes)
kubectl port-forward -n ad-automation svc/auto-put-ad-mini 8080:8080
curl -X POST http://localhost:8080/trigger
import requests
response = requests.post('http://localhost:8080/trigger')
print(response.json())
# 输出示例:
# {
# "status": "triggered",
# "message": "任务已添加到队列"
# }
# 进入Pod
kubectl exec -it -n ad-automation <pod-name> -- bash
# 在Pod内执行
curl -X POST http://localhost:8080/trigger
成功响应:
{
"status": "triggered",
"message": "任务已添加到队列"
}
任务已在运行:
{
"status": "scheduled",
"message": "任务已在队列中",
"next_run": "2026-04-23T03:00:00Z"
}
URL: GET http://localhost:8080/health
curl http://localhost:8080/health | jq .
响应示例:
{
"status": "healthy",
"timestamp": "2026-04-23T15:50:00Z",
"scheduler_running": true,
"latest_report": "llm_decisions_20260423_030000.csv",
"jobs": [
{
"id": "decision_pipeline",
"name": "广告决策流程",
"next_run": "2026-04-24T03:00:00Z"
}
]
}
cd /Users/liulidong/project/agent/Agent/examples/auto_put_ad_mini
# 激活虚拟环境
source .venv/bin/activate
# 启动服务器
python server.py
# 或使用 uvicorn(生产环境)
uvicorn server:app --host 0.0.0.0 --port 8080 --reload
# 构建镜像
docker build -t auto-put-ad-mini:latest .
# 运行容器
docker run -d \
--name auto-put-ad-mini \
--env-file .env \
-p 8080:8080 \
-v $(pwd)/outputs:/app/outputs \
auto-put-ad-mini:latest
# 部署
kubectl apply -f k8s/deployment.yaml
# 查看Pod
kubectl get pods -n ad-automation
# 查看日志
kubectl logs -f -n ad-automation <pod-name>
# 端口转发(本地访问)
kubectl port-forward -n ad-automation svc/auto-put-ad-mini 8080:8080
在数据库中设置 run_on_startup = true:
UPDATE system_config
SET config_value = 'true'
WHERE config_key = 'run_on_startup';
效果: 服务启动后立即执行一次决策流程(不等待定时任务触发)
方法1:暂停调度器(不推荐,会影响手动触发)
方法2:设置一个很晚的时间(如凌晨4点)
UPDATE system_config
SET config_value = '0 20 * * *' -- UTC 20:00 = 北京时间 04:00
WHERE config_key = 'cron_schedule';
# Docker容器
docker logs -f auto-put-ad-mini
# Kubernetes
kubectl logs -f -n ad-automation <pod-name>
# 查看特定时间的日志
kubectl logs -n ad-automation <pod-name> --since=1h
2026-04-23 03:00:00 - INFO - [定时任务] 开始执行决策流程
2026-04-23 03:00:01 - INFO - ✅ 从数据库读取白名单配置:2 个账户
2026-04-23 03:00:05 - INFO - 拉取广告数据完成:100 个广告
2026-04-23 03:02:30 - INFO - AI决策完成:pause(10), bid_down(5), observe(85)
2026-04-23 03:02:35 - INFO - [定时任务] 决策流程执行完成
时区问题
并发控制
执行开关
execution_enabled = false: 只分析不执行(安全模式)execution_enabled = true: 真实执行广告操作(谨慎开启)配置修改生效
检查步骤:
curl http://localhost:8080/health"scheduler_running": true"next_run": "..."SELECT config_value FROM system_config WHERE config_key='cron_schedule'检查步骤:
curl http://localhost:8080/healthkubectl logs -f <pod-name>.env文件中的数据库配置正确解决方法:
0 3 * * *最后更新: 2026-04-23 配置状态: 每天北京时间11:00自动执行 ✅