Menu

1 / 2

Run background tasks with Celery on Vercel - Vercel

Vercel News·Ricardo Gonzalez·5 days ago
#EzaYSkbk
#vercel#celery#task#result#automatically
Reading 0:00
15s threshold

Celery , an asynchronous distributed task queue for Python, is now supported natively on Vercel. Tasks are executed as Vercel Functions and automatically scale with traffic.

from celery import Celery

app = Celery ( "celery" , broker = "vercel://" )

@app . task

def add ( x , y ) :

return x + y

By default, task results are stored in Runtime Cache , which is sufficient for small data sizes and relatively short workflow runtimes. For workloads that require stronger persistence guarantees, more storage or longer retention, a durable result backend can be configured.

from fastapi import FastAPI

from worker import add , app as celery

app = FastAPI ( )

@app . post ( "/add" )

def enqueue ( x : int , y : int ) :

return { "id" : add . delay ( x , y ) . id }

@app . get ( "/result/{task_id}" )

def result ( task_id ) :

task = celery . AsyncResult ( task_id )

return { "status" : task . status , "result" : task .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.