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.
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.
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.
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
¶
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.