Refactor scheduled function execution to use explicit timing control - #82
Refactor scheduled function execution to use explicit timing control#82ianmacartney wants to merge 6 commits into
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository: get-convex/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
commit: |
964b72d to
4864881
Compare
4864881 to
f9d337c
Compare
|
For context, this approach pre-dated the AsyncLocalStorage overhaul, and was an alternative branch to ALS to solve the problem of serializing transactions. #112 is one such manifestation cc @Nicolapps |
|
Replaced by #114 |
Currently a scheduled function uses setTimeout, which can fire mid-way through a transaction if real timers are used. And scheduling multiple functions can also race. This is because they detect the current global transaction lock and infer they're a nested transaction call. This PR waits until the nested transaction has finished before starting the next scheduled function, allowing it to use the global transaction lock to serialize scheduled mutations, regardless of where they're scheduled from or whether real timers are used or not. Fixes #112 Closes #82

Refactor scheduled function execution to use explicit scheduling instead of setTimeout
This change replaces the setTimeout-based scheduled function execution with an explicit scheduling system to reduce races from setTimeout.
Currently, scheduled functions can execute mid-transaction, especially if you don't mock timers.
Key Changes:
finishInProgressScheduledFunctions()andfinishAllScheduledFunctions()scheduledFunctionPathsmap to track resolved function paths for function handles that may target different components than where the job is stored.setTimeoutcall at the scheduled function time sovi.runAllTimers()still works to fast-forward time until all scheduled functions should be enqueued.