cron-demo/app/task.py
giteaadmin 85f2b4fc20
Some checks failed
on-push-smoke / smoke (push) Failing after 2m45s
feat: add continuous cron workflow and sample task
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>
2026-07-30 13:48:09 +00:00

39 lines
1.1 KiB
Python

#!/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()