mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-21 19:52:50 +05:30
refactor: Concurrent batch processing
This commit is contained in:
@@ -362,14 +362,34 @@ async def _process_job_async(job_id: str, transactions: List[Dict[str, Any]]):
|
||||
)
|
||||
try:
|
||||
client = genai.Client(api_key=api_key)
|
||||
# Batch transactions in chunks of 50
|
||||
# Split into batches of 50 and fire all concurrently
|
||||
batch_size = 50
|
||||
for i in range(0, len(uncategorized_txns), batch_size):
|
||||
batch = uncategorized_txns[i : i + batch_size]
|
||||
batch_results = await classify_transactions_batch(
|
||||
client, batch, allowed_categories
|
||||
batches = [
|
||||
uncategorized_txns[i : i + batch_size]
|
||||
for i in range(0, len(uncategorized_txns), batch_size)
|
||||
]
|
||||
logger.info(
|
||||
f"Dispatching {len(batches)} classification batch(es) concurrently..."
|
||||
)
|
||||
with benchmark(
|
||||
"LLM Concurrent Batch Classification (all batches)"
|
||||
):
|
||||
batch_results_list = await asyncio.gather(
|
||||
*[
|
||||
classify_transactions_batch(
|
||||
client, batch, allowed_categories
|
||||
)
|
||||
for batch in batches
|
||||
],
|
||||
return_exceptions=True,
|
||||
)
|
||||
llm_results.update(batch_results)
|
||||
for batch_result in batch_results_list:
|
||||
if isinstance(batch_result, Exception):
|
||||
logger.error(
|
||||
f"A classification batch failed: {batch_result}"
|
||||
)
|
||||
else:
|
||||
llm_results.update(batch_result)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Failed to initialize GenAI Client or classify: {e}"
|
||||
|
||||
0
docs/assets/overview_diagram.svg
Normal file
0
docs/assets/overview_diagram.svg
Normal file
Reference in New Issue
Block a user