@@ -87,23 +87,19 @@ impl AllocationQueueInfo {
8787 fn update_allocation_state (
8888 & mut self ,
8989 allocation_id : & AllocationId ,
90- new_state : AllocationStatus ,
90+ state : AllocationStatus ,
9191 at_time : SystemTime ,
9292 ) {
93- let state = self
94- . allocations
95- . iter_mut ( )
96- . find ( |( id, _) | id == & allocation_id)
97- . map ( |( _, state) | state)
98- . unwrap ( ) ;
99- match new_state {
100- AllocationStatus :: Running => {
101- state. start_time = Some ( at_time) ;
102- }
103- AllocationStatus :: Finished => {
104- state. finish_time = Some ( at_time) ;
93+ if let Some ( info) = self . allocations . get_mut ( allocation_id) {
94+ match state {
95+ AllocationStatus :: Running => {
96+ info. start_time = Some ( at_time) ;
97+ }
98+ AllocationStatus :: Finished => {
99+ info. finish_time = Some ( at_time) ;
100+ }
101+ _ => { }
105102 }
106- _ => { }
107103 }
108104 }
109105}
@@ -125,36 +121,40 @@ impl AllocationTimeline {
125121 ) ;
126122 }
127123 EventPayload :: AllocationQueueRemoved ( queue_id) => {
128- let queue_state = self . queue_timelines . get_mut ( queue_id) . unwrap ( ) ;
129- queue_state. removal_time = Some ( event. time . into ( ) ) ;
124+ if let Some ( queue_state) = self . queue_timelines . get_mut ( queue_id) {
125+ queue_state. removal_time = Some ( event. time . into ( ) ) ;
126+ }
130127 }
131128 EventPayload :: AllocationQueued {
132129 queue_id,
133130 allocation_id,
134131 worker_count,
135132 } => {
136- let queue_state = self . queue_timelines . get_mut ( queue_id) . unwrap ( ) ;
137- queue_state. add_queued_allocation (
138- allocation_id. clone ( ) ,
139- * worker_count,
140- event. time . into ( ) ,
141- ) ;
133+ if let Some ( queue_state) = self . queue_timelines . get_mut ( queue_id) {
134+ queue_state. add_queued_allocation (
135+ allocation_id. clone ( ) ,
136+ * worker_count,
137+ event. time . into ( ) ,
138+ ) ;
139+ }
142140 }
143141 EventPayload :: AllocationStarted ( queue_id, allocation_id) => {
144- let queue_state = self . queue_timelines . get_mut ( queue_id) . unwrap ( ) ;
145- queue_state. update_allocation_state (
146- allocation_id,
147- AllocationStatus :: Running ,
148- event. time . into ( ) ,
149- ) ;
142+ if let Some ( queue_state) = self . queue_timelines . get_mut ( queue_id) {
143+ queue_state. update_allocation_state (
144+ allocation_id,
145+ AllocationStatus :: Running ,
146+ event. time . into ( ) ,
147+ ) ;
148+ }
150149 }
151150 EventPayload :: AllocationFinished ( queue_id, allocation_id) => {
152- let queue_state = self . queue_timelines . get_mut ( queue_id) . unwrap ( ) ;
153- queue_state. update_allocation_state (
154- allocation_id,
155- AllocationStatus :: Finished ,
156- event. time . into ( ) ,
157- ) ;
151+ if let Some ( queue_state) = self . queue_timelines . get_mut ( queue_id) {
152+ queue_state. update_allocation_state (
153+ allocation_id,
154+ AllocationStatus :: Finished ,
155+ event. time . into ( ) ,
156+ ) ;
157+ }
158158 }
159159 _ => { }
160160 }
0 commit comments