Skip to content

(python) FastAPI background tasks not supported #404

@CGarces

Description

@CGarces

Hi!

I'm trying to port this code to lambda using lambda web adapter.

@router.post("/node/", response_model=NodeCreateResponse, status_code=201)
async def create_node_endpoint(background_tasks: BackgroundTasks, node_data: NodeInfoPayload = Body(...)):
    try:
        node =await crud.create_node(node_data.payload)
        background_tasks.add_task(crud.create_connections, node)
        return  JSONResponse(content={"payload":{"id":node.uid,"name":node.name}}, status_code=201)
    except HTTPException as e:
        raise e
    except Exception as e:

        return JSONResponse(content={"error": str(e)}, status_code=400)

After the return function the lambda is finished so the background tasks is never executed.

I assume that this not is supported ¿there is any other options without change too much the source code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions