feat: add continuous cron workflow and sample task
Some checks failed
on-push-smoke / smoke (push) Failing after 2m45s

Add a schedule workflow every 2 minutes with chained jobs,
plus a push smoke workflow to verify the runner immediately.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
giteaadmin 2026-07-30 13:48:09 +00:00
parent 8ab97db76e
commit 85f2b4fc20
4 changed files with 120 additions and 1 deletions

52
.gitea/workflows/cron.yml Normal file
View File

@ -0,0 +1,52 @@
name: continuous-cron
on:
schedule:
# 每 2 分钟触发一次,方便观察连续定时任务
- cron: "*/2 * * * *"
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: prepare marker
run: |
echo "prepare at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "run_id=${{ github.run_id }}"
echo "event=${{ github.event_name }}"
mkdir -p artifacts
echo "prepared" > artifacts/prepare.txt
cat artifacts/prepare.txt
work:
runs-on: ubuntu-latest
needs: prepare
steps:
- name: checkout
uses: actions/checkout@v4
- name: run business task
env:
TASK_OUT_DIR: artifacts
run: |
python3 app/task.py
ls -la artifacts
- name: simulate work
run: |
echo "working..."
sleep 3
echo "work done"
report:
runs-on: ubuntu-latest
needs: work
steps:
- name: summary
run: |
echo "## Continuous Cron Report" >> $GITHUB_STEP_SUMMARY
echo "- run_id: ${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
echo "- event: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "- time_utc: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_STEP_SUMMARY
echo "report finished at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

View File

@ -0,0 +1,17 @@
name: on-push-smoke
on:
push:
branches: [main]
workflow_dispatch:
jobs:
smoke:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: run once
run: |
python3 app/task.py
echo "push smoke ok at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

View File

@ -1,3 +1,15 @@
# cron-demo # cron-demo
连续定时任务测试仓库 用 Gitea Actions 测试连续定时任务的示例仓库。
## 内容
- `app/task.py`:模拟业务任务,每次运行写入一条记录
- `.gitea/workflows/cron.yml`:每 2 分钟定时触发3 个 job 串联
- `.gitea/workflows/on-push.yml`:推送时触发,方便立刻验证 runner
## 本地验证
```bash
python3 app/task.py
```

38
app/task.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
"""模拟定时业务任务:记录每次执行时间与序号。"""
from __future__ import annotations
import json
import os
import socket
import time
from datetime import datetime, timezone
from pathlib import Path
def main() -> None:
run_id = os.environ.get("GITHUB_RUN_ID") or os.environ.get("GITEA_RUN_ID") or "local"
job = os.environ.get("GITHUB_JOB") or "manual"
host = socket.gethostname()
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
ts = int(time.time())
out_dir = Path(os.environ.get("TASK_OUT_DIR") or "artifacts")
out_dir.mkdir(parents=True, exist_ok=True)
record = {
"run_id": run_id,
"job": job,
"host": host,
"utc": now,
"epoch": ts,
"message": f"task ok at {now} on {host}",
}
path = out_dir / f"run-{run_id}-{job}-{ts}.json"
path.write_text(json.dumps(record, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(json.dumps(record, ensure_ascii=False))
print(f"wrote {path}")
if __name__ == "__main__":
main()