@@ -21,7 +21,10 @@ use crate::{artifacts::ArtifactId, metrics::Metrics, PrepareResult, Priority, Pv
2121use always_assert:: { always, never} ;
2222use async_std:: path:: PathBuf ;
2323use futures:: { channel:: mpsc, stream:: StreamExt as _, Future , SinkExt } ;
24- use std:: collections:: { HashMap , VecDeque } ;
24+ use std:: {
25+ collections:: { HashMap , VecDeque } ,
26+ time:: Duration ,
27+ } ;
2528
2629/// A request to pool.
2730#[ derive( Debug ) ]
@@ -30,7 +33,7 @@ pub enum ToQueue {
3033 ///
3134 /// Note that it is incorrect to enqueue the same PVF again without first receiving the
3235 /// [`FromQueue`] response.
33- Enqueue { priority : Priority , pvf : Pvf } ,
36+ Enqueue { priority : Priority , pvf : Pvf , compilation_timeout : Duration } ,
3437}
3538
3639/// A response from queue.
@@ -76,6 +79,8 @@ struct JobData {
7679 /// The priority of this job. Can be bumped.
7780 priority : Priority ,
7881 pvf : Pvf ,
82+ /// The timeout for the preparation job.
83+ compilation_timeout : Duration ,
7984 worker : Option < Worker > ,
8085}
8186
@@ -203,18 +208,24 @@ impl Queue {
203208
204209async fn handle_to_queue ( queue : & mut Queue , to_queue : ToQueue ) -> Result < ( ) , Fatal > {
205210 match to_queue {
206- ToQueue :: Enqueue { priority, pvf } => {
207- handle_enqueue ( queue, priority, pvf) . await ?;
211+ ToQueue :: Enqueue { priority, pvf, compilation_timeout } => {
212+ handle_enqueue ( queue, priority, pvf, compilation_timeout ) . await ?;
208213 } ,
209214 }
210215 Ok ( ( ) )
211216}
212217
213- async fn handle_enqueue ( queue : & mut Queue , priority : Priority , pvf : Pvf ) -> Result < ( ) , Fatal > {
218+ async fn handle_enqueue (
219+ queue : & mut Queue ,
220+ priority : Priority ,
221+ pvf : Pvf ,
222+ compilation_timeout : Duration ,
223+ ) -> Result < ( ) , Fatal > {
214224 gum:: debug!(
215225 target: LOG_TARGET ,
216226 validation_code_hash = ?pvf. code_hash,
217227 ?priority,
228+ ?compilation_timeout,
218229 "PVF is enqueued for preparation." ,
219230 ) ;
220231 queue. metrics . prepare_enqueued ( ) ;
@@ -236,7 +247,7 @@ async fn handle_enqueue(queue: &mut Queue, priority: Priority, pvf: Pvf) -> Resu
236247 return Ok ( ( ) )
237248 }
238249
239- let job = queue. jobs . insert ( JobData { priority, pvf, worker : None } ) ;
250+ let job = queue. jobs . insert ( JobData { priority, pvf, compilation_timeout , worker : None } ) ;
240251 queue. artifact_id_to_job . insert ( artifact_id, job) ;
241252
242253 if let Some ( available) = find_idle_worker ( queue) {
@@ -424,7 +435,12 @@ async fn assign(queue: &mut Queue, worker: Worker, job: Job) -> Result<(), Fatal
424435
425436 send_pool (
426437 & mut queue. to_pool_tx ,
427- pool:: ToPool :: StartWork { worker, code : job_data. pvf . code . clone ( ) , artifact_path } ,
438+ pool:: ToPool :: StartWork {
439+ worker,
440+ code : job_data. pvf . code . clone ( ) ,
441+ artifact_path,
442+ compilation_timeout : job_data. compilation_timeout ,
443+ } ,
428444 )
429445 . await ?;
430446
0 commit comments