Skip to content

fix(cron): accept bare duration units like 'hour' in schedule parsing - #97783

Open
salch-cred wants to merge 1 commit into
NousResearch:mainfrom
salch-cred:fix/cron-bare-duration-units
Open

fix(cron): accept bare duration units like 'hour' in schedule parsing#97783
salch-cred wants to merge 1 commit into
NousResearch:mainfrom
salch-cred:fix/cron-bare-duration-units

Conversation

@salch-cred

Copy link
Copy Markdown
Contributor

Fixes the schedule-parser/UI mismatch where "every hour" (advertised as a valid example) errors with Invalid duration: 'hour', while "every 1h" works.

Root cause

cron/jobs.py parse_duration() matched re.match(r'^(\d+)\s*(...)$') — a leading digit was mandatory. parse_schedule("every hour") strips "every ""hour"parse_duration("hour") failed the regex and raised. Bare-unit phrases like "hour" / "day" had no way to parse.

Fix

Made the leading number optional, defaulting to 1 when absent:

match = re.match(r'^(\d*)\s*(m|min|...|hour|hours|d|day|days)$', s)
value = int(match.group(1)) if match.group(1) else 1

Now "hour" → 60, "day" → 1440, "min" → 1, and existing forms ("30m", "2h", "1d", "every 2h") are unchanged.

Validation

  • parse_duration("hour") → 60; "day" → 1440; "min" → 1.
  • parse_schedule("every hour"){kind: interval, minutes: 60}.
  • Existing "30m", "2h", "1d", "every 2h", "every 30m" all unchanged.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants