-
Notifications
You must be signed in to change notification settings - Fork 272
fix: small scheduler optimizations #2426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces two scheduler improvements: it wraps replenish calls with a timeout to surface slow DB reads, and it corrects snapshot counter behavior to avoid snapshotting on every iteration.
- Wrap replenish with a 2s context timeout inside the ticker loop.
- Increment the snapshot counter to control snapshot frequency.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| innerCtx, cancel := context.WithTimeout(ctx, 2*time.Second) | ||
| err := s.replenish(innerCtx, true) | ||
|
|
||
| if err != nil { | ||
| s.l.Error().Err(err).Msg("error replenishing slots") | ||
| } | ||
| cancel() |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2-second timeout is a magic number. Consider extracting it into a named constant or configuration (e.g., replenishTimeout) to make it easier to tune and document intent.
|
|
||
| s.exts.ReportSnapshot(sqlchelpers.UUIDToStr(s.tenantId), in) | ||
|
|
||
| count++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
Description
Two small optimizations on the scheduler:
replenishmethod so we get errors if database reads are too slowType of change