Where is the source code of the worker that handles scheduled functions?
Hi team, I want to understand how does Convex handle scheduled functions "internally".
I guess it's a worker pool that pick jobs from a queue then execute them. But I want to understand it deeply
Thanks
8 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
GitHub
convex-backend/crates/common/src/bounded_thread_pool.rs at db57318f...
The open-source reactive database for app developers - get-convex/convex-backend
that's the self-hosted impl
of the multi-threaded runner
here's the interface definition for scheduling a job: https://github.com/get-convex/convex-backend/blob/main/crates/isolate/src/client.rs#L281
GitHub
convex-backend/crates/isolate/src/client.rs at main · get-convex/c...
The open-source reactive database for app developers - get-convex/convex-backend
basically, if the mutation commits, then the deployment has a system table called
_scheduled_jobs
which gets a new entry added to it: https://github.com/get-convex/convex-backend/blob/db57318ffa4779d2be212fd89a1c9e737b0fc5a3/npm-packages/system-udfs/convex/schema.ts#L313then this part of the application runtime monitors the scheduled jobs table to find eligible jobs to run: https://github.com/get-convex/convex-backend/blob/db57318ffa4779d2be212fd89a1c9e737b0fc5a3/crates/application/src/scheduled_jobs/mod.rs
GitHub
convex-backend/crates/application/src/scheduled_jobs/mod.rs at db57...
The open-source reactive database for app developers - get-convex/convex-backend
and it uses the running infra I linked to first to run the job: https://github.com/get-convex/convex-backend/blob/db57318ffa4779d2be212fd89a1c9e737b0fc5a3/crates/application/src/scheduled_jobs/mod.rs#L333
GitHub
convex-backend/crates/application/src/scheduled_jobs/mod.rs at db57...
The open-source reactive database for app developers - get-convex/convex-backend
so there's some quick pointers! the runner in the cloud product is actually a distributed service, not an in-process thread pool. that's the difference with the cloud product
hth