Skip to content

Commit

Permalink
auto detect skyvern context and set context if it's not set (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
wintonzheng authored May 7, 2024
1 parent 6473635 commit 0862232
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions skyvern/forge/api_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ async def unexpected_exception(request: Request, exc: Exception) -> JSONResponse

@app.middleware("http")
async def request_middleware(request: Request, call_next: Callable[[Request], Awaitable[Response]]) -> Response:
request_id = str(uuid.uuid4())
skyvern_context.set(SkyvernContext(request_id=request_id))
curr_ctx = skyvern_context.current()
if not curr_ctx:
request_id = str(uuid.uuid4())
skyvern_context.set(SkyvernContext(request_id=request_id))
elif not curr_ctx.request_id:
curr_ctx.request_id = str(uuid.uuid4())

try:
return await call_next(request)
Expand Down

0 comments on commit 0862232

Please sign in to comment.