From 7ea400249590df006e410d0bd718c084bf4dfd9d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 22:40:25 -0700 Subject: [PATCH] =?UTF-8?q?refactor(hermes=5Fcli):=20cron.py=20=E2=80=94?= =?UTF-8?q?=20lift=20manual-run=20verdict=20into=20=5Frun=5Foutcome,=20fla?= =?UTF-8?q?tten=20cron=5Fresume=20mode=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hermes_cli/cron.py | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/hermes_cli/cron.py b/hermes_cli/cron.py index 03d37ed8ca..293b58c879 100644 --- a/hermes_cli/cron.py +++ b/hermes_cli/cron.py @@ -714,46 +714,46 @@ def _job_action(action: str, job_id: str, success_verb: str) -> int: if action in {"resume", "run"} and result.get("job", {}).get("next_run_at"): print(f" Next run: {result['job']['next_run_at']}") if action == "run": - job = result.get("job", {}) - # A manual run may be dispatched to the gateway daemon's background delegation worker - # (execution_mode="background" and/or a delegation_id) and keeps running AFTER this - # CLI exits — a terminal success/failure verdict would be a lie, so report the dispatch. - delegation_id = job.get("delegation_id") - if delegation_id: - print(f" Running in background (delegation {delegation_id}).") - elif job.get("execution_mode") == "background": - print(" Running in background.") - elif job.get("executed"): - print(f" Ran now: {'succeeded' if job.get('execution_success') else 'failed'}.") - elif job.get("execution_skipped"): - print(f" {job['execution_skipped']}") - else: - print(" It will run on the next scheduler tick.") + print(f" {_run_outcome(result.get('job', {}))}") return 0 +def _run_outcome(job: Dict[str, Any]) -> str: + """One-line verdict for a manual run. + + A run may be dispatched to the gateway daemon's background delegation worker + (execution_mode="background" and/or a delegation_id) and keeps running AFTER this CLI + exits — a terminal success/failure verdict would be a lie, so report the dispatch. + """ + if job.get("delegation_id"): + return f"Running in background (delegation {job['delegation_id']})." + if job.get("execution_mode") == "background": + return "Running in background." + if job.get("executed"): + return f"Ran now: {'succeeded' if job.get('execution_success') else 'failed'}." + return job.get("execution_skipped") or "It will run on the next scheduler tick." + + def cron_resume(args) -> int: """Resume a paused job or explicitly re-arm a completed one-shot.""" run_at = getattr(args, "run_at", None) run_now = getattr(args, "run_now", False) - if bool(run_at) == bool(run_now): - if run_at or run_now: - print(color("Use exactly one of --at or --run-now.", Colors.RED)) - return 1 + if run_at and run_now: + print(color("Use exactly one of --at or --run-now.", Colors.RED)) + return 1 + if not run_at and not run_now: return _job_action("resume", args.job_id, "Resumed") from cron.jobs import AmbiguousJobReference, _hermes_now, rearm_oneshot - if run_now: - run_at = _hermes_now().isoformat() try: - job = rearm_oneshot(args.job_id, run_at) + job = rearm_oneshot(args.job_id, _hermes_now().isoformat() if run_now else run_at) except (AmbiguousJobReference, ValueError) as exc: print(color(f"Failed to re-arm job: {exc}", Colors.RED)) return 1 if not job: print(color(f"Job not found: {args.job_id}", Colors.RED)) return 1 - print(color(f"Re-armed job: {job.get('name', args.job_id)} ({args.job_id})", Colors.GREEN)) - print(f" Next run: {job.get('next_run_at')}") + print(color(f"Re-armed job: {job.get('name', args.job_id)} ({args.job_id})", Colors.GREEN) + + f"\n Next run: {job.get('next_run_at')}") return 0