FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add isExecuting() to observe manual execute() runs by sarmah-rup · Pull Request #612 · node-cron/node-cron · GitHub

feat: add isExecuting() to observe manual execute() runs - #612

Open
sarmah-rup wants to merge 1 commit into
node-cron:mainfrom
sarmah-rup:fix/track-invoked-runs
Open

feat: add isExecuting() to observe manual execute() runs#612
sarmah-rup wants to merge 1 commit into
node-cron:mainfrom
sarmah-rup:fix/track-invoked-runs

Conversation

sarmah-rup commented Jul 11, 2026
edited
Loading

Copy link
Copy Markdown

Problem

getStatus() / isBusy() only reflect the scheduled lifecycle, so a run started via execute() (reason 'invoked') is invisible: mid-run getStatus() reports idle and isBusy() returns false. There's no way to poll "is any run in progress right now", which the use case in #611 needs (graceful shutdown that waits for in-flight work; not overlapping a manual run with a scheduled one).

Approach

Following the discussion in #611: execute() deliberately runs outside the state machine (it can run on a stopped task, never counts toward maxExecutions, etc.), so this does not touch getStatus() / isBusy(). Instead it adds a separate signal, as suggested:

  • isExecuting(): boolean — true while any run is actually in flight, scheduled or invoked.

The inline task tracks a small in-flight counter (incremented for every run, so overlapping runs are handled); the background task already keeps an internal executing flag synced over IPC, so it just exposes it. The lifecycle state is untouched: it still flips only for scheduled runs.

Tests

  • Inline: a gated manual execute() shows isExecuting() === true while isBusy() === false / getStatus() === 'idle' (pins the separation), and clears on finish. A scheduled run also reads isExecuting() === true.
  • Background: isExecuting() tracks the execution:started / execution:finished the daemon forwards.

Full suite green (757 tests), 100% coverage on the touched files.

Closes #611

Copy link
Copy Markdown
Member

hello @sarmah-rup thank for the PR, holding on it because the behavior was intentional.

#611 (comment)

getStatus()/isBusy() intentionally reflect only the scheduled lifecycle
state: a manual execute() runs the task function outside the state machine
by design (it can run on a stopped task, never counts toward maxExecutions,
etc). That means a manually invoked run was invisible to any 'is a run in
progress right now' check.

Add isExecuting(), a separate signal that returns true while any run
(scheduled or invoked) is actually in flight, without touching the lifecycle
state. The inline task tracks an in-flight counter; the background task
exposes its existing 'executing' flag over IPC. Use it for graceful
shutdown (wait until no run is in flight) or overlap checks that must also
see manual runs.

Closes node-cron#611
sarmah-rup force-pushed the fix/track-invoked-runs branch from c3b6e8b to ae20a8a Compare July 20, 2026 17:16
sarmah-rup changed the title fix: track invoked runs in isBusy()/getStatus() and noOverlap feat: add isExecuting() to observe manual execute() runs Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

execute() bypasses noOverlap / isBusy() tracking

2 participants


Back | FazBrowse Home | New Git URL