@@ -5,14 +5,12 @@ use crate::internal::common::Set;
55use crate :: internal:: common:: resources:: TimeRequest ;
66use crate :: internal:: common:: resources:: map:: ResourceMap ;
77use crate :: internal:: common:: resources:: { ResourceRequest , ResourceRequestVariants } ;
8- use crate :: internal:: messages:: worker:: ToWorkerMessage ;
9- use crate :: internal:: server:: comm:: Comm ;
108use crate :: internal:: server:: task:: Task ;
119use crate :: internal:: server:: taskmap:: TaskMap ;
1210use crate :: internal:: server:: workerload:: { ResourceRequestLowerBound , WorkerLoad , WorkerResources } ;
1311use crate :: internal:: worker:: configuration:: WorkerConfiguration ;
1412use crate :: { TaskId , WorkerId } ;
15- use std:: time:: Duration ;
13+ use std:: time:: { Duration , Instant } ;
1614
1715bitflags:: bitflags! {
1816 pub ( crate ) struct WorkerFlags : u32 {
@@ -55,12 +53,15 @@ pub struct Worker {
5553 pub ( crate ) resources : WorkerResources ,
5654 pub ( crate ) flags : WorkerFlags ,
5755 // When the worker will be terminated
58- pub ( crate ) termination_time : Option < std :: time :: Instant > ,
56+ pub ( crate ) termination_time : Option < Instant > ,
5957
6058 pub ( crate ) mn_task : Option < MultiNodeTaskAssignment > ,
6159
60+ // Saved timestamp when a worker is put into an idle state
61+ pub ( crate ) idle_timestamp : Instant ,
62+
6263 // COLD DATA move it into a box (?)
63- pub ( crate ) last_heartbeat : std :: time :: Instant ,
64+ pub ( crate ) last_heartbeat : Instant ,
6465 pub ( crate ) configuration : WorkerConfiguration ,
6566}
6667
@@ -123,12 +124,12 @@ impl Worker {
123124
124125 pub fn reset_mn_task ( & mut self ) {
125126 self . mn_task = None ;
127+ self . idle_timestamp = Instant :: now ( ) ;
126128 }
127129
128- pub fn set_reservation ( & mut self , value : bool , comm : & mut impl Comm ) {
130+ pub fn set_reservation ( & mut self , value : bool ) {
129131 if self . is_reserved ( ) != value {
130132 self . flags . set ( WorkerFlags :: RESERVED , value) ;
131- comm. send_worker_message ( self . id , & ToWorkerMessage :: SetReservation ( value) )
132133 }
133134 }
134135
@@ -148,6 +149,9 @@ impl Worker {
148149
149150 pub fn remove_sn_task ( & mut self , task : & Task ) {
150151 assert ! ( self . sn_tasks. remove( & task. id) ) ;
152+ if self . sn_tasks . is_empty ( ) {
153+ self . idle_timestamp = Instant :: now ( ) ;
154+ }
151155 self . sn_load
152156 . remove_request ( task. id , & task. configuration . resources , & self . resources ) ;
153157 }
@@ -205,7 +209,7 @@ impl Worker {
205209 self . flags . contains ( WorkerFlags :: PARKED )
206210 }
207211
208- pub fn is_capable_to_run ( & self , request : & ResourceRequest , now : std :: time :: Instant ) -> bool {
212+ pub fn is_capable_to_run ( & self , request : & ResourceRequest , now : Instant ) -> bool {
209213 self . has_time_to_run ( request. min_time ( ) , now)
210214 && self . resources . is_capable_to_run_request ( request)
211215 }
@@ -221,7 +225,7 @@ impl Worker {
221225 }
222226
223227 // Returns None if there is no time limit for a worker or time limit was passed
224- pub fn remaining_time ( & self , now : std :: time :: Instant ) -> Option < Duration > {
228+ pub fn remaining_time ( & self , now : Instant ) -> Option < Duration > {
225229 self . termination_time . map ( |time| {
226230 if time < now {
227231 Duration :: default ( )
@@ -231,19 +235,15 @@ impl Worker {
231235 } )
232236 }
233237
234- pub fn has_time_to_run ( & self , time_request : TimeRequest , now : std :: time :: Instant ) -> bool {
238+ pub fn has_time_to_run ( & self , time_request : TimeRequest , now : Instant ) -> bool {
235239 if let Some ( time) = self . termination_time {
236240 now + time_request < time
237241 } else {
238242 true
239243 }
240244 }
241245
242- pub fn has_time_to_run_for_rqv (
243- & self ,
244- rqv : & ResourceRequestVariants ,
245- now : std:: time:: Instant ,
246- ) -> bool {
246+ pub fn has_time_to_run_for_rqv ( & self , rqv : & ResourceRequestVariants , now : Instant ) -> bool {
247247 if self . termination_time . is_none ( ) {
248248 return true ;
249249 }
@@ -280,6 +280,7 @@ impl Worker {
280280 flags : WorkerFlags :: empty ( ) ,
281281 last_heartbeat : now,
282282 mn_task : None ,
283+ idle_timestamp : now,
283284 }
284285 }
285286}
0 commit comments