美团券 ETL:prune 防误删护栏 + 每小时定时部署 + meituan_coupon 表文档

- prune 仅在本轮有入库(total>0)时执行,修上游故障时按 last_seen 清空全表的隐患
- 新增 deploy/meituan-etl.{service,timer}:systemd timer 每小时全量灌库(服务器用)
- 新增 docs/database/meituan_coupon.md(字段核对/索引评估/清理策略)并登记索引
This commit is contained in:
chenshuobo
2026-06-10 14:44:40 +08:00
parent db9742f132
commit e92a429ee7
5 changed files with 118 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
# 美团 CPS 券 ETL —— 单轮抓取入库,由 meituan-etl.timer 每小时触发(Linux 服务器用)。
#
# 仅用于 mentor 的 Linux 服务器;本机 Windows 开发无 systemd,直接手动跑脚本即可:
# .venv\Scripts\python -m scripts.pull_meituan_coupons --once --prune-hours 24
#
# 部署(服务器):
# sudo cp deploy/meituan-etl.{service,timer} /etc/systemd/system/
# sudo systemctl daemon-reload && sudo systemctl enable --now meituan-etl.timer
#
# 前置:DATABASE_URL 必须是 postgresql+psycopg://(ETL 的 upsert 是 PG 专用);
# MT_CPS_APP_KEY/SECRET 已配;服务器上 MT_CPS_PROXY 留空(直连)。
[Unit]
Description=Meituan CPS coupon ETL (one-shot, driven by timer)
After=network-online.target postgresql.service
Wants=network-online.target postgresql.service
[Service]
Type=oneshot
User=root
WorkingDirectory=/opt/shaguabijia-app-server
Environment="PATH=/opt/shaguabijia-app-server/.venv/bin:/usr/bin:/bin"
EnvironmentFile=/opt/shaguabijia-app-server/.env
ExecStart=/opt/shaguabijia-app-server/.venv/bin/python -m scripts.pull_meituan_coupons --once --prune-hours 24
SyslogIdentifier=meituan-etl
# 脚本自带 30min 文件锁;给 20min 硬超时,防卡死轮次长期占锁。
TimeoutStartSec=1200
# 与主服务 shaguabijia-app-server.service 同款加固。
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/opt/shaguabijia-app-server
ProtectHome=true
+14
View File
@@ -0,0 +1,14 @@
# 每小时触发一次美团 CPS 券 ETL(Linux 服务器用)。
# 见 meituan-etl.service 顶部注释的部署步骤。
[Unit]
Description=Run Meituan CPS coupon ETL hourly
[Timer]
# 每小时第 5 分钟跑,避开整点其它定时任务扎堆。
OnCalendar=*-*-* *:05:00
# 服务器宕机/重启后,补跑错过的那一轮(而不是干等下一个整点)。
Persistent=true
AccuracySec=1min
[Install]
WantedBy=timers.target