Skip to content

log the scheduled function in work:start#171

Merged
ianmacartney merged 1 commit intomainfrom
ian/log-scheduled-function
Mar 2, 2026
Merged

log the scheduled function in work:start#171
ianmacartney merged 1 commit intomainfrom
ian/log-scheduled-function

Conversation

@ianmacartney
Copy link
Member

@ianmacartney ianmacartney commented Mar 2, 2026

TL;DR

Added scheduled function ID tracking to work execution logging by capturing the return value from scheduler calls and passing it to the recordStarted function.

What changed?

  • Modified beginWork function to await and capture the scheduleId from ctx.scheduler.runAfter() calls for both action and mutation/query function types
  • Updated recordStarted function signature to accept a scheduledFunctionId parameter
  • Moved the recordStarted call to after the scheduler operations complete so the schedule ID can be included
  • Added scheduledFunctionId field to the logged event data

How to test?

Execute work items of different function types (actions, mutations, queries) and verify that the logged events now include the scheduledFunctionId field with the correct scheduled function ID.

Why make this change?

This enables better traceability and debugging by linking work execution events with their corresponding scheduled function entries, making it easier to track the lifecycle of work items through the scheduling system.

Summary by CodeRabbit

  • Chores
    • Enhanced internal tracking of background operations for improved correlation and monitoring.
    • Started events now include identifiers linking scheduled work to its execution for better observability.
    • Minor sequencing adjustments to ensure the scheduler ID is captured and reported consistently.

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed93b4a and 21d679e.

📒 Files selected for processing (2)
  • src/component/loop.ts
  • src/component/stats.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/component/stats.ts
  • src/component/loop.ts

📝 Walkthrough

Walkthrough

The change captures the schedule ID returned by ctx.scheduler.runAfter in beginWork, passes it to recordStarted, and updates recordStarted to accept and include scheduledFunctionId in the started event payload (signature updated).

Changes

Cohort / File(s) Summary
Schedule ID Propagation
src/component/loop.ts, src/component/stats.ts
beginWork now awaits ctx.scheduler.runAfter into a local scheduleId variable, calls recordStarted(console, work, lagMs, scheduleId), and returns scheduleId. recordStarted signature updated to accept scheduledFunctionId and include it in the started event payload.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through code at break of dawn,
I caught the ID before it was gone,
I passed it gently into stats’ care,
Now logs and schedules match, pair by pair. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding scheduled function logging to the work:start event by capturing and recording the scheduledFunctionId.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ian/log-scheduled-function

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ianmacartney ianmacartney marked this pull request as ready for review March 2, 2026 02:46
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/component/loop.ts`:
- Line 565: Declare scheduleId with the correct explicit type to satisfy strict
mode: change the untyped `let scheduleId;` to `let scheduleId:
Id<"_scheduled_functions">` (or the nullable/undefined variant if it can be
uninitialized) so it matches the expected parameter type for `recordStarted()`
and the function return `Promise<Id<"_scheduled_functions">>`; update any
control flow to initialize or narrow the type accordingly before passing it into
`recordStarted()` or returning it from the async function.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed6875 and ed93b4a.

📒 Files selected for processing (2)
  • src/component/loop.ts
  • src/component/stats.ts

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/workpool/@convex-dev/workpool@171

commit: 21d679e

@ianmacartney ianmacartney force-pushed the ian/log-scheduled-function branch from ed93b4a to 21d679e Compare March 2, 2026 03:03
@ianmacartney ianmacartney merged commit 21d679e into main Mar 2, 2026
4 checks passed
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