fix: use is_job_runnable/effective_job_state in remaining pause-check sites
Two claim-failure diagnostic paths (cronjob_tools.py:629,921) still used the old inline 'not enabled or state==paused' check. After get_job() normalizes via effective_job_state, a half-paused record has state='scheduled' and enabled=True, so the inline check returned False — mislabeling the job as 'already being fired' instead of 'paused/disabled'. Also hoists effective_job_state/is_job_runnable to the top-level import in cronjob_tools.py (was function-local) and updates console_engine.py's _format_job to use effective_job_state instead of the old inline state-or-enabled derivation — a fourth display path the original PR missed. Follow-up to PR #81287.
This commit is contained in:
@@ -148,9 +148,11 @@ def _format_sessions(sessions: Sequence[dict]) -> str:
|
||||
|
||||
|
||||
def _format_job(job: dict, action: str) -> str:
|
||||
from cron.jobs import effective_job_state
|
||||
|
||||
job_id = job.get("id") or job.get("job_id") or "?"
|
||||
name = job.get("name") or "(unnamed)"
|
||||
state = job.get("state") or ("scheduled" if job.get("enabled", True) else "paused")
|
||||
state = effective_job_state(job)
|
||||
return f"{action} job: {name} ({job_id}) [{state}]"
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
from cron.jobs import (
|
||||
AmbiguousJobReference,
|
||||
claim_job_for_fire,
|
||||
effective_job_state,
|
||||
get_job,
|
||||
is_job_runnable,
|
||||
list_jobs,
|
||||
mark_job_run,
|
||||
parse_schedule,
|
||||
@@ -552,8 +554,6 @@ def _validate_cron_script_path(script: Optional[str]) -> Optional[str]:
|
||||
|
||||
|
||||
def _format_job(job: Dict[str, Any]) -> Dict[str, Any]:
|
||||
from cron.jobs import effective_job_state
|
||||
|
||||
prompt = str(job.get("prompt") or "")
|
||||
skills = _canonical_skills(job.get("skill"), job.get("skills"))
|
||||
job_id = str(job.get("id") or "unknown")
|
||||
@@ -626,7 +626,7 @@ def _execute_job_now(
|
||||
refreshed = get_job(job_id)
|
||||
if refreshed is None:
|
||||
reason = "Job no longer exists; nothing to run."
|
||||
elif not refreshed.get("enabled", True) or refreshed.get("state") == "paused":
|
||||
elif not is_job_runnable(refreshed):
|
||||
reason = "Job is paused/disabled; resume it before running."
|
||||
else:
|
||||
reason = "Job is already being fired by the scheduler; not run again."
|
||||
@@ -918,7 +918,7 @@ def _try_dispatch_background_run(
|
||||
refreshed = get_job(job_id)
|
||||
if refreshed is None:
|
||||
reason = "Job no longer exists; nothing to run."
|
||||
elif not refreshed.get("enabled", True) or refreshed.get("state") == "paused":
|
||||
elif not is_job_runnable(refreshed):
|
||||
reason = "Job is paused/disabled; resume it before running."
|
||||
else:
|
||||
reason = "Job is already being fired by the scheduler; not run again."
|
||||
|
||||
Reference in New Issue
Block a user