feat: add lastRun() introspection getter#557
Merged
Merged
Conversation
Add a lastRun() method to the ScheduledTask interface returning info about
the last actual execution, or null if the task has not run yet. The return
type is { date, result } on success or { date, error } on failure, where
date reflects when the execution really ran (the execution's own finish
time), not when a scheduler tick was merely checked.
Implemented for both inline and background tasks. The inline task records
it from the runner's finished/error hooks; the background task mirrors it
in the parent from the daemon's forwarded events, coercing IPC-serialized
timestamps back to Date.
The defensive timestamp fallbacks in recordLastRun were uncovered, which dropped coverage. The runner always sets finishedAt before the finished/failed hooks (scheduler/runner.ts), so the inline path now reads it directly instead of branching through startedAt/new Date(). The background path keeps the IPC string coercion and now has tests for the startedAt fallback, the no-timestamp fallback, and the no-execution guard.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
lastRun()introspection getter to the publicScheduledTaskinterface. It returns information about the last actual execution of a task, ornullif the task has not run yet.Return type (
LastRun, exported from the package):{ date, result }.{ date, error }.null.Key semantics
datereflects when the execution actually ran (the execution's own finish time), not when a scheduler tick was merely checked. This avoids the well-known competitor bug of reporting the tick-check time instead of the real execution time. The value is taken from the runner's per-executionfinishedAt(falling back tostartedAt), which is stamped the moment the task settles.Implementation
onFinished/onErrorhooks, which already carry theExecutionobject with its real timestamps, result, and error.execution:finished/execution:failedevents, coercing IPC-serialized timestamps back toDate.LastRunis exported from the package entry point and appears in the generated.d.ts.Tests
Added coverage for both task types:
nullbefore the first executionDate(background)npm run check(lint + vitest with coverage) passes fully: 384 tests,src/tasksinline/interface files at 100% coverage.Docs
README updated with a short runtime-introspection example covering
getNextRun()andlastRun().