API reference
PULQ — fair pull-based task scheduling with WDRR.
- class pulq.CommandDispatcher
Bases:
objectFIFO of
ManagementCommandperworker_id.- take_next_for(worker_id)
Pop the next command for
worker_id(must callhas_pending_for()first).- Return type:
- class pulq.CommandType(*values)
Bases:
StrEnumManagement commands targeted at a worker.
- STOP = 'stop'
- PAUSE = 'pause'
- RESUME = 'resume'
- class pulq.DeficitScheduler(config)
Bases:
objectTracks WDRR deficits for fair weighted service among priority buckets.
Each scheduling epoch credits every priority with its configured weight. Work claims debit
quantumfrom the served priority. Empty priorities are zeroed so the scheduler does not stall on idle buckets.
- class pulq.DeficitSchedulerConfig(**data)
Bases:
BaseModelValidated parameters for
DeficitScheduler.priority_orderdefines visit order among buckets that share a claimable deficit.weightsmust contain exactly one positive integer weight per priority inpriority_order, and no other keys.- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.HeartbeatCallback(*args, **kwargs)
Bases:
ProtocolOptional hook invoked when a worker requests work.
- class pulq.InMemoryTaskRepository
Bases:
objectFIFO pending queues per priority with atomic claim semantics.
- async claim_next_pending(priority, worker_id)
Pop oldest pending task for
priorityand mark it RUNNING.- Return type:
- class pulq.LocalTransport(queue)
Bases:
objectIn-process transport delegating to
PullQueue.- async request_work(worker_id)
Delegate to
pulq.core.pull_queue.PullQueue.get_next().- Return type:
- async report_completion(task_id, result)
Delegate to
pulq.core.pull_queue.PullQueue.mark_complete().- Return type:
- class pulq.ManagementCommand(**data)
Bases:
BaseModelHigh-priority instruction for a specific worker.
- command: CommandType
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.NoPendingTask(**data)
Bases:
BaseModelNull object: no pending task was available for this priority.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.NoWork(**data)
Bases:
BaseModelNull object: pull succeeded but there is nothing to execute.
- reason: NoWorkReason
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.NoWorkReason(*values)
Bases:
StrEnumWhy the queue returned no schedulable work.
- QUEUE_EMPTY = 'queue_empty'
- ALL_PRIORITIES_STARVED = 'all_priorities_starved'
- class pulq.PullQueue(repository, *, priority_order, weights, quantum=1, commands=None, deficits=None, on_heartbeat=None)
Bases:
objectCoordinates deficit scheduling, per-worker commands, and task claims.
- property commands: CommandDispatcher
Management command queues (same instance shared if injected).
- property deficits: DeficitScheduler
WDRR deficit ledger.
- send_command(worker_id, command)
Queue a management command for
worker_id(synchronous enqueue).- Return type:
- async mark_complete(task_id, result)
Mark
task_idcomplete;resultfollows handler conventions.- Return type:
- async get_next(worker_id)
Pull the next management command, schedulable task, or
NoWork.- Return type:
- class pulq.Task(**data)
Bases:
BaseModelA unit of work with a priority bucket for WDRR scheduling.
- status: TaskStatus
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.TaskHandler(*args, **kwargs)
Bases:
ProtocolUser-defined async handler for
Taskexecution.
- class pulq.TaskRepository(*args, **kwargs)
Bases:
ProtocolStorage backend for pending tasks (implement with DB, Redis, etc.).
- async claim_next_pending(priority, worker_id)
Atomically claim the next pending task for
priority, if any.- Return type:
- async mark_complete(task_id, result)
Mark a task completed and return the updated record.
- Return type:
- class pulq.TaskStatus(*values)
Bases:
StrEnumLifecycle state of a task.
- PENDING = 'pending'
- RUNNING = 'running'
- COMPLETED = 'completed'
- FAILED = 'failed'
- class pulq.Transport(*args, **kwargs)
Bases:
ProtocolHow a worker obtains work and reports completion (local, HTTP, …).
- async request_work(worker_id)
Pull the next schedulable item for
worker_id.- Return type:
- class pulq.Worker(transport, worker_id, handler, *, no_work_delay_seconds=0.0, startup=None, shutdown=None, before_process=None, after_process=None)
Bases:
objectPull loop: commands, tasks, and optional backoff on
NoWork.
- pulq.parse_claim_result(data)
Parse a mapping into a
ClaimResultunion using Pydantic discriminated union.- Return type:
- pulq.parse_work_response(data)
Parse a mapping into a
WorkResponseunion using Pydantic discriminated union.- Return type:
Pull queue orchestrating WDRR, management commands, and storage.
- class pulq.core.pull_queue.PullQueue(repository, *, priority_order, weights, quantum=1, commands=None, deficits=None, on_heartbeat=None)
Coordinates deficit scheduling, per-worker commands, and task claims.
- property commands: CommandDispatcher
Management command queues (same instance shared if injected).
- property deficits: DeficitScheduler
WDRR deficit ledger.
- send_command(worker_id, command)
Queue a management command for
worker_id(synchronous enqueue).- Return type:
- async mark_complete(task_id, result)
Mark
task_idcomplete;resultfollows handler conventions.- Return type:
- async get_next(worker_id)
Pull the next management command, schedulable task, or
NoWork.- Return type:
Weighted Deficit Round Robin (WDRR) deficit ledger.
- class pulq.core.scheduler.DeficitScheduler(config)
Tracks WDRR deficits for fair weighted service among priority buckets.
Each scheduling epoch credits every priority with its configured weight. Work claims debit
quantumfrom the served priority. Empty priorities are zeroed so the scheduler does not stall on idle buckets.
Per-worker management command queues.
- class pulq.core.dispatcher.CommandDispatcher
FIFO of
ManagementCommandperworker_id.- take_next_for(worker_id)
Pop the next command for
worker_id(must callhas_pending_for()first).- Return type:
Async worker that pulls tasks via a Transport.
- class pulq.core.worker.Worker(transport, worker_id, handler, *, no_work_delay_seconds=0.0, startup=None, shutdown=None, before_process=None, after_process=None)
Pull loop: commands, tasks, and optional backoff on
NoWork.
Enumerations shared by task and work-item models.
- class pulq.models.enums.CommandType(*values)
Management commands targeted at a worker.
- STOP = 'stop'
- PAUSE = 'pause'
- RESUME = 'resume'
- class pulq.models.enums.NoWorkReason(*values)
Why the queue returned no schedulable work.
- QUEUE_EMPTY = 'queue_empty'
- ALL_PRIORITIES_STARVED = 'all_priorities_starved'
- class pulq.models.enums.TaskStatus(*values)
Lifecycle state of a task.
- PENDING = 'pending'
- RUNNING = 'running'
- COMPLETED = 'completed'
- FAILED = 'failed'
Task document model.
- class pulq.models.task.Task(**data)
A unit of work with a priority bucket for WDRR scheduling.
- status: TaskStatus
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Management commands and null-object work responses.
- class pulq.models.work.ManagementCommand(**data)
High-priority instruction for a specific worker.
- command: CommandType
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.models.work.NoPendingTask(**data)
Null object: no pending task was available for this priority.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pulq.models.work.NoWork(**data)
Null object: pull succeeded but there is nothing to execute.
- reason: NoWorkReason
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Discriminated union type aliases for API boundaries.
Pydantic configuration for WDRR deficit scheduling.
- class pulq.models.scheduler_config.DeficitSchedulerConfig(**data)
Validated parameters for
DeficitScheduler.priority_orderdefines visit order among buckets that share a claimable deficit.weightsmust contain exactly one positive integer weight per priority inpriority_order, and no other keys.- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Parse untrusted mappings into typed work and claim results.
- pulq.parsing.parse_claim_result(data)
Parse a mapping into a
ClaimResultunion using Pydantic discriminated union.- Return type:
- pulq.parsing.parse_work_response(data)
Parse a mapping into a
WorkResponseunion using Pydantic discriminated union.- Return type:
In-memory task repository for tests and single-process workloads.
- class pulq.storage.memory.InMemoryTaskRepository
FIFO pending queues per priority with atomic claim semantics.
- async claim_next_pending(priority, worker_id)
Pop oldest pending task for
priorityand mark it RUNNING.- Return type:
In-process transport: direct calls into PullQueue.
- class pulq.transport.local.LocalTransport(queue)
In-process transport delegating to
PullQueue.- async request_work(worker_id)
Delegate to
pulq.core.pull_queue.PullQueue.get_next().- Return type:
- async report_completion(task_id, result)
Delegate to
pulq.core.pull_queue.PullQueue.mark_complete().- Return type:
Protocols and callback types.
- class pulq.types.HeartbeatCallback(*args, **kwargs)
Optional hook invoked when a worker requests work.
- class pulq.types.TaskHandler(*args, **kwargs)
User-defined async handler for
Taskexecution.
- class pulq.types.TaskRepository(*args, **kwargs)
Storage backend for pending tasks (implement with DB, Redis, etc.).
- async claim_next_pending(priority, worker_id)
Atomically claim the next pending task for
priority, if any.- Return type:
- async mark_complete(task_id, result)
Mark a task completed and return the updated record.
- Return type: