Implement FastAPI Temporal MVP pipeline
This commit is contained in:
35
app/infra/temporal/client.py
Normal file
35
app/infra/temporal/client.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Temporal client helpers."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from temporalio.client import Client
|
||||
|
||||
from app.config.settings import get_settings
|
||||
|
||||
_client: Client | None = None
|
||||
_client_lock = asyncio.Lock()
|
||||
|
||||
|
||||
async def get_temporal_client() -> Client:
|
||||
"""Return a cached Temporal client."""
|
||||
|
||||
global _client
|
||||
if _client is not None:
|
||||
return _client
|
||||
|
||||
async with _client_lock:
|
||||
if _client is None:
|
||||
settings = get_settings()
|
||||
_client = await Client.connect(
|
||||
settings.temporal_address,
|
||||
namespace=settings.temporal_namespace,
|
||||
)
|
||||
return _client
|
||||
|
||||
|
||||
def set_temporal_client(client: Client | None) -> None:
|
||||
"""Override the cached Temporal client, primarily for tests."""
|
||||
|
||||
global _client
|
||||
_client = client
|
||||
|
||||
Reference in New Issue
Block a user