From 07f21a5511c7fc3c260a9c39e558087fbf3a2b26 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Sun, 9 Jun 2024 18:14:42 +0300 Subject: [PATCH] Github: work in background --- pr_agent/servers/github_app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index be141084..9361d595 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -7,6 +7,7 @@ from typing import Any, Dict, Tuple import uvicorn from fastapi import APIRouter, FastAPI, HTTPException, Request, Response +from starlette.background import BackgroundTasks from starlette.middleware import Middleware from starlette_context import context from starlette_context.middleware import RawContextMiddleware @@ -34,7 +35,7 @@ router = APIRouter() @router.post("/api/v1/github_webhooks") -async def handle_github_webhooks(request: Request, response: Response): +async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Request, response: Response): """ Receives and processes incoming GitHub webhook requests. Verifies the request signature, parses the request body, and passes it to the handle_request function for further @@ -48,8 +49,8 @@ async def handle_github_webhooks(request: Request, response: Response): context["installation_id"] = installation_id context["settings"] = copy.deepcopy(global_settings) - response = await handle_request(body, event=request.headers.get("X-GitHub-Event", None)) - return response or {} + background_tasks.add_task(handle_request, body, event=request.headers.get("X-GitHub-Event", None)) + return {} @router.post("/api/v1/marketplace_webhooks")