Run APScheduler coroutine jobs on a portal loop - #270
Open
ricardo-agz wants to merge 1 commit into
Open
Conversation
The inline executor rejected coroutine jobs whenever a loop was already running, which is every queue worker delivery: vercel-queue invokes sync subscription handlers on its own event loop thread, so async jobs on a stock AsyncIOScheduler never executed on Vercel. Run them on a process-lifetime AnyIO blocking portal instead. A single persistent loop also replaces the per-call asyncio.run of the sync path, so loop-bound resources a job creates (async clients, locks) remain valid between runs, matching what a stock AsyncIOScheduler provides.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Fixes coroutine jobs never executing on Vercel: the inline executor rejected them whenever an event loop was already running, and every queue worker delivery runs on one (vercel-queue invokes sync subscription handlers on its event loop thread).
Coroutine jobs now run on a process-lifetime AnyIO blocking portal. One persistent loop rather than a loop per run also means loop-bound resources a job creates (async Redis clients, locks) stay valid across runs, which is the same contract a stock AsyncIOScheduler gives jobs by running them all on its loop.
The sync-context path changes accordingly: previously each run got a fresh
asyncio.runloop, which invalidated those same resources between runs.Found by a stock FastAPI + AsyncIOScheduler demo whose
async defjob failed on every delivery with "cannot run APScheduler async jobs from a running event loop".