@hivey/cli 0.9.58 → 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
|
@@ -102,7 +102,30 @@ def log_path(command: str) -> str | None:
|
|
|
102
102
|
return os.path.expanduser(m.group(1)) if m else None
|
|
103
103
|
|
|
104
104
|
|
|
105
|
-
def
|
|
105
|
+
def _is_err(line: str) -> bool:
|
|
106
|
+
# "N Failed downloads:" is yfinance warning about delisted tickers, not a failed run
|
|
107
|
+
return bool(re.search(r"error|traceback|exception|failed|fatal", line, re.I)
|
|
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))
|
|
110
|
+
|
|
111
|
+
|
|
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:
|
|
106
129
|
if not path or not os.path.isfile(path):
|
|
107
130
|
return {}
|
|
108
131
|
st = os.stat(path)
|
|
@@ -112,9 +135,13 @@ def log_info(path: str | None) -> dict:
|
|
|
112
135
|
f.seek(max(0, st.st_size - 6000))
|
|
113
136
|
tail = f.read().decode("utf-8", "replace").splitlines()[-40:]
|
|
114
137
|
tail = [re.sub(r"\x1b\[[0-9;]*[A-Za-z]|\r", "", l)[:300] for l in tail]
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
# logs are appended run after run: an error from an earlier run that a later run's success line
|
|
139
|
+
# follows is history, not a current problem (a Baserow timeout stayed flagged after good runs)
|
|
140
|
+
ok = re.compile(r"\b(success(ful(ly)?)?|succeeded|finished|completed?|done|wrote|all ok)\b", re.I)
|
|
141
|
+
last_ok = max((i for i, l in enumerate(tail) if ok.search(l) and not _is_err(l)), default=-1)
|
|
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)]
|
|
118
145
|
if errs:
|
|
119
146
|
info["last_error"] = errs[-1][:200]
|
|
120
147
|
info["errors"] = list(dict.fromkeys(e[:200] for e in errs))[-5:]
|
|
@@ -154,10 +181,14 @@ def cron_jobs() -> list[dict]:
|
|
|
154
181
|
catchup[parts[0]] = (parts[1], parts[2])
|
|
155
182
|
for name, (sched, cmd) in catchup.items():
|
|
156
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}"
|
|
157
188
|
jobs.append({
|
|
158
189
|
"id": f"cron:{name}", "name": name, "kind": "cron (cron-catchup)", "schedule": sched,
|
|
159
|
-
"command": cmd, "agent": job_agent(cmd), "status":
|
|
160
|
-
"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),
|
|
161
192
|
})
|
|
162
193
|
for line in sh(["crontab", "-l"]).splitlines():
|
|
163
194
|
s = line.strip()
|