chore: switch mac2 scheduling to crontab
This commit is contained in:
@@ -41,21 +41,23 @@ scripts/run_pipeline.sh --start-date 2026-10-10 --end-date 2026-10-16
|
||||
|
||||
`index.html` 是无构建依赖的静态页面,读取并校验 `data/index.json` 及其清单,支持日期范围、包名筛选和表头排序。直接打开文件或执行 `python3 -m http.server` 后访问即可。
|
||||
|
||||
## mac2 launchd
|
||||
## mac2 crontab
|
||||
|
||||
launchd 会调用 `scripts/run_pipeline.sh`,因此也使用 sibling 项目 `.env` 中的凭据;模板通过 `PYTHON_BIN` 传入 mac2 的 Python 路径,并保留工作目录和 stdout/stderr 日志路径:
|
||||
mac2 使用 crontab 定时调用 `scripts/run_pipeline.sh`。包装脚本会读取 sibling 项目 `.env` 中的凭据,因此 cron 环境不需要配置密钥。先确认手工执行成功,再编辑当前用户的 crontab:
|
||||
|
||||
```sh
|
||||
cd /Users/shareit./Library/CloudStorage/OneDrive-个人/ubuntu/Gitea/af-click-gap
|
||||
mkdir -p "$HOME/Library/Logs/af-click-gap" "$HOME/Library/LaunchAgents"
|
||||
PY=$(command -v python3)
|
||||
sed -e "s#__MAC2_PYTHON3__#$PY#" -e "s#__PROJECT_DIR__#$PWD#g" -e "s#__LOG_DIR__#$HOME/Library/Logs/af-click-gap#g" launchd/com.roasbloom.af-click-gap.plist.template > /tmp/com.roasbloom.af-click-gap.plist
|
||||
plutil -lint /tmp/com.roasbloom.af-click-gap.plist
|
||||
cp /tmp/com.roasbloom.af-click-gap.plist "$HOME/Library/LaunchAgents/"
|
||||
launchctl bootstrap "gui/$(id -u)" "$HOME/Library/LaunchAgents/com.roasbloom.af-click-gap.plist"
|
||||
scripts/run_pipeline.sh
|
||||
crontab -e
|
||||
```
|
||||
|
||||
卸载:`launchctl bootout "gui/$(id -u)/com.roasbloom.af-click-gap"` 后删除 LaunchAgents 中的 plist。日志写在 mac2 用户日志目录;数据库、`.env`、密钥、日志和缓存均不会提交。
|
||||
加入以下示例(每天 mac2 本地时间 06:10 运行;请按实际 Python 路径和日志位置调整):
|
||||
|
||||
```cron
|
||||
10 6 * * * cd /Users/shareit./Library/CloudStorage/OneDrive-个人/ubuntu/Gitea/af-click-gap && /usr/bin/env PYTHON_BIN=/usr/bin/python3 ./scripts/run_pipeline.sh >> "$HOME/Library/Logs/af-click-gap/cron.log" 2>&1
|
||||
```
|
||||
|
||||
创建日志目录:`mkdir -p "$HOME/Library/Logs/af-click-gap"`。数据库、`.env`、密钥、日志和缓存均不会提交;不再使用或保留系统级 plist 配置。
|
||||
|
||||
## Git 创建和推送
|
||||
|
||||
@@ -66,7 +68,6 @@ launchctl bootstrap "gui/$(id -u)" "$HOME/Library/LaunchAgents/com.roasbloom.af-
|
||||
```sh
|
||||
python3 -m py_compile scripts/af_click_gap_pipeline.py
|
||||
python3 scripts/af_click_gap_pipeline.py --help
|
||||
plutil -lint launchd/com.roasbloom.af-click-gap.plist.template
|
||||
python3 -m json.tool data/index.json
|
||||
```
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<!-- TEMPLATE_ONLY: render and validate on mac2 before installing. -->
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>Label</key><string>com.roasbloom.af-click-gap</string>
|
||||
<key>ProgramArguments</key><array><string>__PROJECT_DIR__/scripts/run_pipeline.sh</string></array>
|
||||
<key>EnvironmentVariables</key><dict><key>PYTHON_BIN</key><string>__MAC2_PYTHON3__</string></dict>
|
||||
<key>WorkingDirectory</key><string>__PROJECT_DIR__</string>
|
||||
<key>StartCalendarInterval</key><dict><key>Hour</key><integer>2</integer><key>Minute</key><integer>0</integer></dict>
|
||||
<key>StandardOutPath</key><string>__LOG_DIR__/pipeline.stdout.log</string><key>StandardErrorPath</key><string>__LOG_DIR__/pipeline.stderr.log</string>
|
||||
<key>RunAtLoad</key><false/>
|
||||
</dict></plist>
|
||||
Reference in New Issue
Block a user