fix: sync import in dispatch callback (#3275)

This commit is contained in:
cthomas
2025-07-10 15:03:01 -07:00
committed by GitHub
parent 9390da1e2a
commit 64058c407d
2 changed files with 6 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ from functools import partial, reduce
from operator import add
from typing import List, Literal, Optional, Union
from httpx import AsyncClient, post
from sqlalchemy import select
from sqlalchemy.orm import Session
@@ -683,10 +684,8 @@ class JobManager:
"metadata": job.metadata_,
}
try:
import httpx
log_event("POST callback dispatched", payload)
resp = httpx.post(job.callback_url, json=payload, timeout=5.0)
resp = post(job.callback_url, json=payload, timeout=5.0)
log_event("POST callback finished")
job.callback_sent_at = get_utc_time().replace(tzinfo=None)
job.callback_status_code = resp.status_code
@@ -712,9 +711,7 @@ class JobManager:
}
try:
import httpx
async with httpx.AsyncClient() as client:
async with AsyncClient() as client:
log_event("POST callback dispatched", payload)
resp = await client.post(job.callback_url, json=payload, timeout=5.0)
log_event("POST callback finished")

View File

@@ -8,8 +8,6 @@ import time
from datetime import datetime, timedelta, timezone
from typing import List
import httpx
# tests/test_file_content_flow.py
import pytest
from _pytest.python_api import approx
@@ -6001,7 +5999,9 @@ async def test_e2e_job_callback(monkeypatch, server: SyncServer, default_user):
return await mock_post(url, json, timeout)
# Patch the AsyncClient
monkeypatch.setattr(httpx, "AsyncClient", MockAsyncClient)
import letta.services.job_manager as job_manager_module
monkeypatch.setattr(job_manager_module, "AsyncClient", MockAsyncClient)
job_in = PydanticJob(status=JobStatus.created, metadata={"foo": "bar"}, callback_url="http://example.test/webhook/jobs")
created = await server.job_manager.create_job_async(pydantic_job=job_in, actor=default_user)