Skip to content

prefactor_core.queue.executor module

Task executor for processing queue items asynchronously.

The TaskExecutor manages a pool of async workers that continuously pull items from a queue and process them using a handler function.

class prefactor_core.queue.executor.TaskExecutor(queue: Queue[Any], handler: Callable[[Any], Awaitable[None]], num_workers: int = 3, max_retries: int = 3, , is_retryable: Callable[[Exception], bool] | None = None)

Section titled “class prefactor_core.queue.executor.TaskExecutor(queue: Queue[Any], handler: Callable[[Any], Awaitable[None]], num_workers: int = 3, max_retries: int = 3, , is_retryable: Callable[[Exception], bool] | None = None)”

Bases: object

Manages async workers that process queue items.

The executor runs a configurable number of worker tasks that continuously pull items from the queue and process them. If processing fails, items are retried with exponential backoff.

async def handler(item: str) -> None: : print(f”Processing: {item}”)

queue = InMemoryQueue() executor = TaskExecutor(queue, handler, num_workers=3) executor.start()

await queue.put(“item1”) await queue.put(“item2”)

await executor.stop()

Start the worker tasks.

Workers will begin pulling items from the queue immediately.

Stop all workers gracefully.

Closes the queue (so no new items can be added), wakes any workers blocked in get(), and waits for them to drain the remaining items and exit on their own. Workers are never cancelled — that would discard already-queued items.