feat: task introspection (getNextRuns, match, msToNext, isBusy, runsLeft, getPattern) by merencia · Pull Request #547 · node-cron/node-cron · GitHub
Skip to content

feat: task introspection (getNextRuns, match, msToNext, isBusy, runsLeft, getPattern)#547

Merged
merencia merged 2 commits into
mainfrom
feat/task-introspection
Jun 17, 2026
Merged

feat: task introspection (getNextRuns, match, msToNext, isBusy, runsLeft, getPattern)#547
merencia merged 2 commits into
mainfrom
feat/task-introspection

Conversation

@merencia

Copy link
Copy Markdown
Member

Phase 1 — task introspection. Six small methods on the public ScheduledTask interface, implemented for both inline and background tasks.

Method Returns Notes
getNextRuns(n) Date[] the next n matches from now (pure; closes the FI-7 scenario skipped in the DST work)
match(date) boolean whether a date matches the expression
msToNext() number | null ms until the next run; null when stopped
isBusy() boolean whether an execution is in progress
runsLeft() number | undefined remaining runs when maxExecutions is set
getPattern() string the original cron expression
  • getNextRuns / match / getPattern are pure (computed from the expression + timezone), so they work on a stopped task and on a background task without querying the daemon.
  • runsLeft for background tasks: the real count lives in the forked daemon, so the parent mirrors it from the execution:started events it already receives.

Tests cover both implementations (inline directly; background for the local-compute methods and the event-tracked runsLeft). Full suite green.

Next in Phase 1

  • cron.parse() + cron.validateDetailed() (expression introspection — separate PR).
  • Observability (getStats/history/previousRun(s)) after the EventStore provider.

merencia added 2 commits June 17, 2026 15:37
Add getNextRuns(n), match(date), msToNext(), isBusy(), runsLeft() and
getPattern() to the public ScheduledTask interface, implemented for both inline
and background tasks.

- getNextRuns / match / getPattern are pure (computed from the expression and
  timezone), so they work on a stopped task and on background tasks without
  querying the daemon.
- msToNext / isBusy reflect live state.
- runsLeft mirrors the runner's count; background tasks track it from the
  forwarded execution:started events since the real count lives in the daemon.
These two introspection methods on BackgroundScheduledTask were untested,
dropping coverage. Add the missing cases (msToNext null when stopped + positive
once started; isBusy false when idle).
@merencia merencia merged commit 394e57e into main Jun 17, 2026
6 checks passed
@merencia merencia mentioned this pull request Jun 18, 2026
merencia added a commit that referenced this pull request Jun 18, 2026
Promote the Unreleased section to 4.4.0 and bump the version.

Highlights (all additive, backwards-compatible):
- Task introspection: getNextRuns, match, msToNext, isBusy, runsLeft, getPattern (#547)
- cron.parse and cron.validateDetailed (#548)
- Distributed run coordination: distributed:true + NODE_CRON_RUN default + RunCoordinator (#549)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant