Repository navigation
Can the server run a scheduled job or a background task? #597
|
I want the server to do something on its own every night, such as cleaning up old rows or sending a summary. Can I start a scheduler or an asyncio task when the app starts? |
Replies: 1 comment
|
Applies to: any version — this is how the project works by design. Scheduled work must not depend on a task that outlives its request. Vercel can suspend the process between requests. The host target is long-running, but the project still uses an external tick for scheduled work. Local bot polling is a separate lifespan task. Everything on a clock goes through the tick,
Work that follows a single request, such as a notice after a write, runs inside that request, after its commit. |
Applies to: any version — this is how the project works by design.
Scheduled work must not depend on a task that outlives its request. Vercel can suspend the process between requests. The host target is long-running, but the project still uses an external tick for scheduled work. Local bot polling is a separate lifespan task.
Everything on a clock goes through the tick,
GET|POST /api/v1/cron/tick(tickinserver/app/api/cron.py). An external cron service calls the tick every five minutes withX-Cron-Secret. To add a job:services/. Call it fromtick.