1717//! A queue that handles requests for PVF preparation.
1818
1919use super :: pool:: { self , Worker } ;
20- use crate :: { artifacts:: ArtifactId , metrics:: Metrics , Priority , Pvf , LOG_TARGET } ;
20+ use crate :: {
21+ artifacts:: { ArtifactId , PrepareError } ,
22+ metrics:: Metrics ,
23+ Priority , Pvf , LOG_TARGET ,
24+ } ;
2125use always_assert:: { always, never} ;
2226use async_std:: path:: PathBuf ;
2327use futures:: { channel:: mpsc, stream:: StreamExt as _, Future , SinkExt } ;
@@ -37,9 +41,13 @@ pub enum ToQueue {
3741}
3842
3943/// A response from queue.
40- #[ derive( Debug , PartialEq , Eq ) ]
41- pub enum FromQueue {
42- Prepared ( ArtifactId ) ,
44+ #[ derive( Debug ) ]
45+ pub struct FromQueue {
46+ /// Identifier of an artifact.
47+ pub ( crate ) artifact_id : ArtifactId ,
48+ /// Outcome of the PVF processing. [`Ok`] indicates that compiled artifact
49+ /// is successfully stored on disk. Otherwise, an [error](PrepareError) is supplied.
50+ pub ( crate ) result : Result < ( ) , PrepareError > ,
4351}
4452
4553#[ derive( Default ) ]
@@ -299,7 +307,8 @@ async fn handle_from_pool(queue: &mut Queue, from_pool: pool::FromPool) -> Resul
299307 use pool:: FromPool :: * ;
300308 match from_pool {
301309 Spawned ( worker) => handle_worker_spawned ( queue, worker) . await ?,
302- Concluded ( worker, rip) => handle_worker_concluded ( queue, worker, rip) . await ?,
310+ Concluded { worker, rip, result } =>
311+ handle_worker_concluded ( queue, worker, rip, result) . await ?,
303312 Rip ( worker) => handle_worker_rip ( queue, worker) . await ?,
304313 }
305314 Ok ( ( ) )
@@ -320,6 +329,7 @@ async fn handle_worker_concluded(
320329 queue : & mut Queue ,
321330 worker : Worker ,
322331 rip : bool ,
332+ result : Result < ( ) , PrepareError > ,
323333) -> Result < ( ) , Fatal > {
324334 queue. metrics . prepare_concluded ( ) ;
325335
@@ -377,7 +387,7 @@ async fn handle_worker_concluded(
377387 "prepare worker concluded" ,
378388 ) ;
379389
380- reply ( & mut queue. from_queue_tx , FromQueue :: Prepared ( artifact_id) ) ?;
390+ reply ( & mut queue. from_queue_tx , FromQueue { artifact_id, result } ) ?;
381391
382392 // Figure out what to do with the worker.
383393 if rip {
@@ -641,12 +651,9 @@ mod tests {
641651
642652 let w = test. workers . insert ( ( ) ) ;
643653 test. send_from_pool ( pool:: FromPool :: Spawned ( w) ) ;
644- test. send_from_pool ( pool:: FromPool :: Concluded ( w, false ) ) ;
654+ test. send_from_pool ( pool:: FromPool :: Concluded { worker : w, rip : false , result : Ok ( ( ) ) } ) ;
645655
646- assert_eq ! (
647- test. poll_and_recv_from_queue( ) . await ,
648- FromQueue :: Prepared ( pvf( 1 ) . as_artifact_id( ) )
649- ) ;
656+ assert_eq ! ( test. poll_and_recv_from_queue( ) . await . artifact_id, pvf( 1 ) . as_artifact_id( ) ) ;
650657 }
651658
652659 #[ async_std:: test]
@@ -671,7 +678,7 @@ mod tests {
671678 assert_matches ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: StartWork { .. } ) ;
672679 assert_matches ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: StartWork { .. } ) ;
673680
674- test. send_from_pool ( pool:: FromPool :: Concluded ( w1, false ) ) ;
681+ test. send_from_pool ( pool:: FromPool :: Concluded { worker : w1, rip : false , result : Ok ( ( ) ) } ) ;
675682
676683 assert_matches ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: StartWork { .. } ) ;
677684
@@ -704,7 +711,7 @@ mod tests {
704711 // That's a bit silly in this context, but in production there will be an entire pool up
705712 // to the `soft_capacity` of workers and it doesn't matter which one to cull. Either way,
706713 // we just check that edge case of an edge case works.
707- test. send_from_pool ( pool:: FromPool :: Concluded ( w1, false ) ) ;
714+ test. send_from_pool ( pool:: FromPool :: Concluded { worker : w1, rip : false , result : Ok ( ( ) ) } ) ;
708715 assert_eq ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: Kill ( w1) ) ;
709716 }
710717
@@ -749,15 +756,12 @@ mod tests {
749756 assert_matches ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: StartWork { .. } ) ;
750757
751758 // Conclude worker 1 and rip it.
752- test. send_from_pool ( pool:: FromPool :: Concluded ( w1, true ) ) ;
759+ test. send_from_pool ( pool:: FromPool :: Concluded { worker : w1, rip : true , result : Ok ( ( ) ) } ) ;
753760
754761 // Since there is still work, the queue requested one extra worker to spawn to handle the
755762 // remaining enqueued work items.
756763 assert_eq ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: Spawn ) ;
757- assert_eq ! (
758- test. poll_and_recv_from_queue( ) . await ,
759- FromQueue :: Prepared ( pvf( 1 ) . as_artifact_id( ) )
760- ) ;
764+ assert_eq ! ( test. poll_and_recv_from_queue( ) . await . artifact_id, pvf( 1 ) . as_artifact_id( ) ) ;
761765 }
762766
763767 #[ async_std:: test]
@@ -773,7 +777,7 @@ mod tests {
773777
774778 assert_matches ! ( test. poll_and_recv_to_pool( ) . await , pool:: ToPool :: StartWork { .. } ) ;
775779
776- test. send_from_pool ( pool:: FromPool :: Concluded ( w1, true ) ) ;
780+ test. send_from_pool ( pool:: FromPool :: Concluded { worker : w1, rip : true , result : Ok ( ( ) ) } ) ;
777781 test. poll_ensure_to_pool_is_empty ( ) . await ;
778782 }
779783
0 commit comments