File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 39
39
40
40
41
41
class Scheduler (SchedulerInterface ):
42
+
43
+ # Policy mapping for efficient policy lookup
44
+ _POLICY_MAPPING = {
45
+ "priority" : SchedulingPolicy .PRIORITY ,
46
+ "fcfs" : SchedulingPolicy .FCFS ,
47
+ }
42
48
43
49
def __init__ (
44
50
self ,
@@ -99,13 +105,10 @@ def __init__(
99
105
# req_id -> Request
100
106
self .requests : dict [str , Request ] = {}
101
107
# Scheduling policy
102
- if self .scheduler_config .policy == "priority" :
103
- self .policy = SchedulingPolicy .PRIORITY
104
- elif self .scheduler_config .policy == "fcfs" :
105
- self .policy = SchedulingPolicy .FCFS
106
- else :
107
- raise ValueError (
108
- f"Unknown scheduling policy: { self .scheduler_config .policy } " )
108
+ policy_name = self .scheduler_config .policy
109
+ if policy_name not in self ._POLICY_MAPPING :
110
+ raise ValueError (f"Unknown scheduling policy: { policy_name } " )
111
+ self .policy = self ._POLICY_MAPPING [policy_name ]
109
112
# Priority queues for requests.
110
113
self .waiting = create_request_queue (self .policy )
111
114
self .running : list [Request ] = []
You can’t perform that action at this time.
0 commit comments