Skip to content

OSSS.ai.dependencies.resource_scheduler

OSSS.ai.dependencies.resource_scheduler

Resource scheduling system with priority-based execution and concurrency constraints.

This module provides sophisticated resource management for agent execution including resource pools, scheduling policies, priority queuing, and concurrency control.

ResourceType

Bases: Enum

Types of resources that can be managed.

SchedulingPolicy

Bases: Enum

Scheduling policies for resource allocation.

ResourceState

Bases: Enum

States of resource allocation.

ResourceRequest

Bases: BaseModel

Request for resource allocation.

Migrated from dataclass to Pydantic BaseModel for enhanced validation, serialization, and integration with the OSSS Pydantic ecosystem.

is_expired()

Check if request has expired based on max wait time.

get_wait_time_ms()

Get current wait time in milliseconds.

is_deadline_approaching(threshold_ms=5000)

Check if deadline is approaching within threshold.

ResourceAllocation

Bases: BaseModel

Represents an active resource allocation.

Migrated from dataclass to Pydantic BaseModel for enhanced validation, serialization, and integration with the OSSS Pydantic ecosystem.

get_age_ms()

Get age of allocation in milliseconds.

is_overdue()

Check if allocation is overdue for release.

ResourcePool

Bases: BaseModel

Pool of resources with capacity and allocation tracking.

Migrated from dataclass to Pydantic BaseModel for enhanced validation, serialization, and integration with the OSSS Pydantic ecosystem.

model_post_init(__context)

Post-initialization to set computed fields.

can_allocate(amount, exclusive=False)

Check if the requested amount can be allocated.

allocate(request)

Allocate resources for a request.

release(allocation_id)

Release an allocation.

get_utilization()

Get current utilization percentage (0-100).

get_available_percentage()

Get available capacity percentage (0-100).

is_near_capacity(threshold=0.9)

Check if pool is near capacity.

get_overdue_allocations()

Get allocations that are overdue for release.

cleanup_expired_allocations()

Cleanup expired allocations and return count cleaned up.

PriorityQueue

Priority queue for resource requests.

enqueue(request)

Add a request to the queue.

dequeue()

Remove and return the highest priority request.

peek()

Look at the next request without removing it.

remove(request_id)

Remove a specific request from the queue.

size()

Get queue size.

is_empty()

Check if queue is empty.

ResourceScheduler

Advanced resource scheduler with priority-based execution and concurrency control.

Manages multiple resource pools, handles scheduling policies, and provides comprehensive resource allocation and monitoring capabilities.

add_resource_pool(pool)

Add a resource pool to the scheduler.

create_standard_pools()

Create standard resource pools with default configurations.

request_resources(agent_id, resources, priority=ExecutionPriority.NORMAL, estimated_duration_ms=None, deadline=None) async

Request resources for an agent.

Parameters

agent_id : str ID of the requesting agent resources : List[ResourceConstraint] List of resource constraints/requirements priority : ExecutionPriority Execution priority estimated_duration_ms : Optional[int] Estimated duration of resource usage deadline : Optional[float] Deadline for resource allocation

Returns

List[str] List of request IDs for tracking

release_resources(agent_id, allocation_ids=None) async

Release resources for an agent.

Parameters

agent_id : str ID of the agent releasing resources allocation_ids : Optional[List[str]] Specific allocation IDs to release (if None, releases all for agent)

Returns

bool True if all resources were successfully released

get_resource_utilization()

Get utilization statistics for all resource pools.

get_agent_allocations(agent_id)

Get all active allocations for a specific agent.

get_scheduling_statistics()

Get comprehensive scheduling statistics.

optimize_allocations() async

Optimize current allocations for better resource utilization.