Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

941
Vistas
Python: FastAPI & Celery tasks class. NotImplementedError: No result backend is configured

I'm developping an API where users can send me POST requests. When requests are received, I want a queue to process their.

When my data requests are pushed on the celery Queue, I want my workers (remote server) to handle their.

For this, I use:

  • celery version 5.1.0 for workers
  • RabbitMQ version 3.9 for messages

I want my code to follow Class Programming methods so I would like to use Celery.Task class.

My code belwo:

  • server.py: is my FASTAPI application & endpoints. It should handle my task called client
  • tasks.py: is my celery.Celery instance & celery.Task classes.
# server.py

# Module imports
from fastapi import (
    FastAPI,
    Request
)
from fastapi.responses import (
    JSONResponse
)
import uvicorn

# Own module
from tasks import (
    client,
    add
)

# Environment
app = FastAPI()

# Endpoints
@app.post('/post/{name}')
def get_post(request: Request, name: str):
    result_not_working = client.delay(1, 2) # Not working
    result_working = add.delay(1, 2) # Working
    return JSONResponse(status_code=200, content={"status": 200, "message": f"You post {result.get()}"})

if __name__ == "__main__":
    uvicorn.run(app, host='', port=)



# tasks.py
from celery import (
    Celery,
    Task
)

# Environment
app = Celery('test_celery',
             broker=f"amqp://RABBITMQ_USER:RABBITMQ_PWD@RABBITMQ_HOST:RABBITMQ_PORT/RABBITMQ_DB",
             backend='rpc://')

# Class
class Client(Task):
    name = "tasks.PandasClient"
    def run(self, x, y, **kwargs):
        return x + y

@app.task(name="add")
def add(x, y):
    return x + y

client = Client()
app.tasks.register(client)

There is my problem: When I called my client object in server.py (client is an instance of Client, which is registered into my Celery queue), i get the error:

NotImplementedError: No result backend is configured.

BUT when I import and call my add function in server.py, it works with no problems.

Strange thing, when I run my worker with the command celery -A tasks worker --loglevel=info, I can see:

enter image description here

It tells me my broker url is correctly set, so why not my backend (which works when I call the function add not the class Client.run)

The documentation does not explain how to build Task class

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I found the solution,

instead of registering my task with:

app.tasks.register(client)

I wrote:

app.register_task(client)

and it works.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda