@@ -33,6 +33,8 @@ use nativelink_util::task::JoinHandleDropGuard;
3333use tokio:: sync:: Notify ;
3434use tokio:: sync:: mpsc:: { self , UnboundedSender } ;
3535use tonic:: async_trait;
36+ #[ cfg( feature = "worker_find_logging" ) ]
37+ use tracing:: info;
3638use tracing:: { error, warn} ;
3739
3840use crate :: platform_property_manager:: PlatformPropertyManager ;
@@ -191,21 +193,46 @@ impl ApiWorkerSchedulerImpl {
191193 Ok ( ( ) )
192194 }
193195
196+ #[ cfg_attr( not( feature = "worker_find_logging" ) , allow( unused_variables) ) ]
197+ fn inner_worker_checker (
198+ ( worker_id, w) : & ( & WorkerId , & Worker ) ,
199+ platform_properties : & PlatformProperties ,
200+ ) -> bool {
201+ #[ cfg( feature = "worker_find_logging" ) ]
202+ {
203+ if !w. can_accept_work ( ) {
204+ info ! (
205+ "Worker {worker_id} cannot accept work because is_paused: {}, is_draining: {}" ,
206+ w. is_paused, w. is_draining
207+ ) ;
208+ return false ;
209+ }
210+ if !platform_properties. is_satisfied_by ( & w. platform_properties ) {
211+ info ! ( "Worker {worker_id} properties are insufficient" ) ;
212+ return false ;
213+ }
214+ return true ;
215+ }
216+ #[ cfg( not( feature = "worker_find_logging" ) ) ]
217+ {
218+ w. can_accept_work ( ) && platform_properties. is_satisfied_by ( & w. platform_properties )
219+ }
220+ }
221+
194222 fn inner_find_worker_for_action (
195223 & self ,
196224 platform_properties : & PlatformProperties ,
197225 ) -> Option < WorkerId > {
198226 let mut workers_iter = self . workers . iter ( ) ;
199- let workers_iter = match self . allocation_strategy {
200- // Use rfind to get the least recently used that satisfies the properties.
201- WorkerAllocationStrategy :: LeastRecentlyUsed => workers_iter. rfind ( |( _, w) | {
202- w. can_accept_work ( ) && platform_properties. is_satisfied_by ( & w. platform_properties )
203- } ) ,
204- // Use find to get the most recently used that satisfies the properties.
205- WorkerAllocationStrategy :: MostRecentlyUsed => workers_iter. find ( |( _, w) | {
206- w. can_accept_work ( ) && platform_properties. is_satisfied_by ( & w. platform_properties )
207- } ) ,
208- } ;
227+ let workers_iter =
228+ match self . allocation_strategy {
229+ // Use rfind to get the least recently used that satisfies the properties.
230+ WorkerAllocationStrategy :: LeastRecentlyUsed => workers_iter
231+ . rfind ( |worker| Self :: inner_worker_checker ( worker, platform_properties) ) ,
232+ // Use find to get the most recently used that satisfies the properties.
233+ WorkerAllocationStrategy :: MostRecentlyUsed => workers_iter
234+ . find ( |worker| Self :: inner_worker_checker ( worker, platform_properties) ) ,
235+ } ;
209236 workers_iter. map ( |( _, w) | w. id . clone ( ) )
210237 }
211238
0 commit comments