fffiloni commited on
Commit
c4ac2fb
·
verified ·
1 Parent(s): b67c03f

Upload hello_worker.py

Browse files
Files changed (1) hide show
  1. web/hello_worker.py +53 -0
web/hello_worker.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Standalone version of the first worker.
2
+
3
+ The orchestrator currently embeds an equivalent script into the Job environment as
4
+ base64 to keep the first deployment self-contained. This file exists so the
5
+ worker logic is easy to inspect, test, and evolve in the next increments.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import os
12
+ from datetime import datetime, timezone
13
+ from pathlib import Path
14
+
15
+
16
+ def now() -> str:
17
+ return datetime.now(timezone.utc).isoformat()
18
+
19
+
20
+ def write_json(path: Path, payload: dict) -> None:
21
+ path.parent.mkdir(parents=True, exist_ok=True)
22
+ path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
23
+
24
+
25
+ def append_event(path: Path, step: str, status: str, message: str, data: dict | None = None) -> None:
26
+ path.parent.mkdir(parents=True, exist_ok=True)
27
+ event = {"ts": now(), "step": step, "status": status, "message": message, "data": data or {}}
28
+ with path.open("a", encoding="utf-8") as f:
29
+ f.write(json.dumps(event, ensure_ascii=False) + "\n")
30
+
31
+
32
+ def main() -> None:
33
+ run_id = os.environ["RUN_ID"]
34
+ output_root = Path(os.environ.get("OUTPUT_ROOT", "/output"))
35
+ run_dir = output_root / "runs" / run_id
36
+ events_path = run_dir / "events.jsonl"
37
+
38
+ append_event(events_path, "bootstrap", "started", "Standalone worker started")
39
+ write_json(
40
+ run_dir / "state.json",
41
+ {
42
+ "run_id": run_id,
43
+ "status": "success",
44
+ "message": "Standalone hello worker completed.",
45
+ "updated_at": now(),
46
+ },
47
+ )
48
+ (run_dir / "report.md").write_text("# Hello Worker\n\nSuccess.\n", encoding="utf-8")
49
+ append_event(events_path, "done", "success", "Standalone worker completed")
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()