@hivey/cli 0.9.59 → 0.9.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/package.json
CHANGED
|
@@ -103,11 +103,29 @@ def log_path(command: str) -> str | None:
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
def _is_err(line: str) -> bool:
|
|
106
|
+
# "N Failed downloads:" is yfinance warning about delisted tickers, not a failed run
|
|
106
107
|
return bool(re.search(r"error|traceback|exception|failed|fatal", line, re.I)
|
|
107
|
-
and not re.search(r"\b0 failed|failed:? 0\b|0 errors?\b|errors?:? 0\b|rerun picks",
|
|
108
|
+
and not re.search(r"\b0 failed|failed:? 0\b|0 errors?\b|errors?:? 0\b|rerun picks|failed downloads?:",
|
|
109
|
+
line, re.I))
|
|
108
110
|
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
# the first and last line of an uncaught Python traceback; an uncaught one always exits non-zero
|
|
113
|
+
CRASH_RE = re.compile(r"^\s*(Traceback \(most recent call last\)|[\w.]+(Error|Exception|Interrupt|Exit)\b)")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def last_exit(name: str) -> int | None:
|
|
117
|
+
"""Exit code of a cron-catchup job's latest finished run (from ~/logs/cron-catchup/<name>.log)."""
|
|
118
|
+
f = HOME / "logs" / "cron-catchup" / f"{name}.log"
|
|
119
|
+
try:
|
|
120
|
+
with open(f, "rb") as fh:
|
|
121
|
+
fh.seek(max(0, f.stat().st_size - 2000))
|
|
122
|
+
codes = re.findall(r"finished \S+ \S+ exit (-?\d+)", fh.read().decode("utf-8", "replace"))
|
|
123
|
+
return int(codes[-1]) if codes else None
|
|
124
|
+
except OSError:
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def log_info(path: str | None, exit_code: int | None = None) -> dict:
|
|
111
129
|
if not path or not os.path.isfile(path):
|
|
112
130
|
return {}
|
|
113
131
|
st = os.stat(path)
|
|
@@ -122,6 +140,8 @@ def log_info(path: str | None) -> dict:
|
|
|
122
140
|
ok = re.compile(r"\b(success(ful(ly)?)?|succeeded|finished|completed?|done|wrote|all ok)\b", re.I)
|
|
123
141
|
last_ok = max((i for i, l in enumerate(tail) if ok.search(l) and not _is_err(l)), default=-1)
|
|
124
142
|
errs = [l.strip() for l in tail[last_ok + 1:] if _is_err(l)]
|
|
143
|
+
if exit_code == 0: # the latest run exited 0, so any traceback still in the tail is from an earlier run
|
|
144
|
+
errs = [l for l in errs if not CRASH_RE.match(l)]
|
|
125
145
|
if errs:
|
|
126
146
|
info["last_error"] = errs[-1][:200]
|
|
127
147
|
info["errors"] = list(dict.fromkeys(e[:200] for e in errs))[-5:]
|
|
@@ -161,10 +181,14 @@ def cron_jobs() -> list[dict]:
|
|
|
161
181
|
catchup[parts[0]] = (parts[1], parts[2])
|
|
162
182
|
for name, (sched, cmd) in catchup.items():
|
|
163
183
|
st = catchup_status.get(name, {})
|
|
184
|
+
rc = last_exit(name)
|
|
185
|
+
state = st.get("state", "?")
|
|
186
|
+
if rc and state == "ok": # ran on time but failed: show the exit code, not "ran ok"
|
|
187
|
+
state = f"exit {rc}"
|
|
164
188
|
jobs.append({
|
|
165
189
|
"id": f"cron:{name}", "name": name, "kind": "cron (cron-catchup)", "schedule": sched,
|
|
166
|
-
"command": cmd, "agent": job_agent(cmd), "status":
|
|
167
|
-
"last_run": st.get("last_run"), **log_info(log_path(cmd)),
|
|
190
|
+
"command": cmd, "agent": job_agent(cmd), "status": state,
|
|
191
|
+
"last_run": st.get("last_run"), **log_info(log_path(cmd), rc),
|
|
168
192
|
})
|
|
169
193
|
for line in sh(["crontab", "-l"]).splitlines():
|
|
170
194
|
s = line.strip()
|