Skip to content

Batch processing blocks the async event loop #10

@jtdub

Description

@jtdub

Problem

create_batch_remediation() in batch.py:25 calls PlatformService.process_batch_job() synchronously inside an async endpoint:

PlatformService.process_batch_job(job_data)

This blocks the entire event loop for the duration of the batch, preventing the server from handling any other requests. For a batch of many devices, this could block for a significant time.

The docs describe batch processing as "parallel," but the implementation is sequential and blocking.

Suggested Fix

  • Use asyncio.to_thread() or FastAPI's BackgroundTasks to run batch processing off the event loop.
  • Return a 202 Accepted with the job ID immediately, and let the client poll /batch/jobs/{id} for status.
  • Consider concurrent.futures.ProcessPoolExecutor for true parallelism across devices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions