Skip to content

fix(cron): support standard 5-field crontabs, validate schedules, and improve schedule descriptions - #596

Open
madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:feat/better-crontab-support
Open

madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:feat/better-crontab-support

Conversation

@madejackson

@madejackson madejackson commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fixes #554

Three related fixes for the scheduled jobs (cron) feature.

1. Support standard 5-field crontabs + validate schedules (src/cron/crontab.go)

The scheduler previously forced every crontab through gocron's withSeconds=true parser, which requires exactly 6 fields. Any standard 5-field expression (0 2 * * *) failed to parse and was silently dropped from the schedule (only logged as a MajorError), so those jobs never ran. The UI helper had the same 6-field-only assumption.

This introduces a dual-format scheme:

  • 5-field standard crontabs (minute hour dom month dow)
  • 6-field seconds-first crontabs (the Cosmos UI format)
  • descriptors (@daily, @every 10m, …) and CRON_TZ= / TZ= prefixes

Invalid/ambiguous expressions are now rejected loudly instead of silently never running.

All stored crontabs are normalized to the canonical 6-field form:

  • scheduler normalizes on load (heals legacy 5-field configs)
  • /api/cron create/update validate + normalize (new CR013/CR014/CR023/CR024)
  • backups add/edit validate + normalize (BCK008/BCK009)
  • restic + snapraid job registration normalizes before scheduling

UI:

  • crontabToText understands 5-field, 6-field, descriptors and TZ prefixes
  • new isValidCrontab helper with inline validation on the cron job, backup, and snapraid dialogs

Tests: NormalizeCrontab/ValidCrontab unit tests (src/cron/crontab_test.go).

2. Rewrite crontab descriptions + let them wrap in tables (client/src/utils/indexs.js)

crontabToText previously produced redundant, zero-heavy output such as "Every day, Every day at 3 hours and 0 min and 0 sec" for 0 0 3 * * *. Rewritten to emit concise natural-language descriptions:

Crontab Description
0 0 3 * * * every day at 03:00
*/5 * * * * every 5 minutes
0 12 * * 1-5 every week on Monday to Friday at 12:00
30 4 1,15 * * every month on the 1st, 15th at 04:30
0 0 4 */2 * * every 2 days at 04:00
  • specific times use 24h clock format
  • weekday mapping follows robfig/cron POSIX convention (0=Sunday … 6=Saturday)
  • skips zero-valued seconds/minutes
  • keep descriptors (@daily, @every 90m) and TZ= prefixes working

Descriptions can be long, so the schedule column now wraps (white-space: normal + break-word) in the cron jobs, backups, SnapRAID parity tables, and the backup overview info blocks — instead of being clipped by the default nowrap table cell.

3. Keep TextField labels above prefilled values in the cron job dialog (client/src/pages/cron/newJob.jsx)

When editing a cron job that already has a Command (or Crontab) value, the MUI outlined field's floating label overlapped the value because the label only shrinks on focus/useFormik mount, but the edit path populates the value asynchronously via formik.setValues() after mount. The label now stays shrunk whenever the field already holds a value, so the descriptive label sits above the text instead of overlapping it.

Verification

  • go build ./... ✅
  • go test ./src/cron/... ✅
  • npm run client-build (vite) ✅

All 3 commits are cherry-picked onto the current azukaar/Cosmos-Server:unstable (0b5a43e).

@cla-bot cla-bot Bot added the cla-signed label Sep 4, 2026
@madejackson
madejackson force-pushed the feat/better-crontab-support branch 2 times, most recently from 2b6aa4d to 2d49763 Compare September 8, 2026 18:44
@madejackson
madejackson force-pushed the feat/better-crontab-support branch 2 times, most recently from 9b8cc4b to b0b58c1 Compare October 9, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant