@@ -7,8 +7,7 @@ use crate::load::{partition_in_place, SiteCtxt};
77use chrono:: Utc ;
88use collector:: benchmark_set:: benchmark_set_count;
99use database:: {
10- BenchmarkJob , BenchmarkJobStatus , BenchmarkRequest , BenchmarkRequestIndex ,
11- BenchmarkRequestStatus , Target ,
10+ BenchmarkJob , BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , Target ,
1211} ;
1312use hashbrown:: HashSet ;
1413use parking_lot:: RwLock ;
@@ -198,14 +197,12 @@ pub fn create_benchmark_jobs(
198197 ) {
199198 for backend in backends. iter ( ) {
200199 for profile in profiles. iter ( ) {
201- let job = BenchmarkJob :: new (
200+ let job = BenchmarkJob :: create_queued (
202201 target,
203202 * backend,
204203 * profile,
205204 benchmark_request. tag ( ) . unwrap ( ) ,
206205 benchmark_set as u32 ,
207- Utc :: now ( ) ,
208- BenchmarkJobStatus :: Queued ,
209206 ) ;
210207 jobs. push ( job) ;
211208 }
@@ -218,35 +215,46 @@ pub fn create_benchmark_jobs(
218215
219216/// Enqueue the job into the job_queue
220217async fn enqueue_next_job (
221- conn : & dyn database:: pool:: Connection ,
218+ conn : & mut dyn database:: pool:: Connection ,
222219 index : & mut BenchmarkRequestIndex ,
223220) -> anyhow:: Result < ( ) > {
224221 let queue = build_queue ( conn, index) . await ?;
222+ let mut tx = conn. transaction ( ) . await ;
225223 for request in queue {
226224 if request. status ( ) != BenchmarkRequestStatus :: InProgress {
227- for job in create_benchmark_jobs ( & request) ? {
228- conn. enqueue_benchmark_job ( & job) . await ?;
225+ for benchmark_job in create_benchmark_jobs ( & request) ? {
226+ tx. conn ( )
227+ . enqueue_benchmark_job (
228+ benchmark_job. request_tag ( ) ,
229+ & benchmark_job. target ( ) ,
230+ & benchmark_job. backend ( ) ,
231+ & benchmark_job. profile ( ) ,
232+ benchmark_job. benchmark_set ( ) ,
233+ )
234+ . await ?;
229235 }
230- conn. update_benchmark_request_status (
231- request. tag ( ) . unwrap ( ) ,
232- BenchmarkRequestStatus :: InProgress ,
233- )
234- . await ?;
236+ tx. conn ( )
237+ . update_benchmark_request_status (
238+ request. tag ( ) . unwrap ( ) ,
239+ BenchmarkRequestStatus :: InProgress ,
240+ )
241+ . await ?;
235242 break ;
236243 }
237244 }
245+ tx. commit ( ) . await ?;
238246 Ok ( ( ) )
239247}
240248
241249/// For queueing jobs, add the jobs you want to queue to this function
242250async fn cron_enqueue_jobs ( site_ctxt : & Arc < SiteCtxt > ) -> anyhow:: Result < ( ) > {
243- let conn = site_ctxt. conn ( ) . await ;
251+ let mut conn = site_ctxt. conn ( ) . await ;
244252 let mut index = conn. load_benchmark_request_index ( ) . await ?;
245253 // Put the master commits into the `benchmark_requests` queue
246254 create_benchmark_request_master_commits ( site_ctxt, & * conn, & index) . await ?;
247255 // Put the releases into the `benchmark_requests` queue
248256 create_benchmark_request_releases ( & * conn, & index) . await ?;
249- enqueue_next_job ( & * conn, & mut index) . await ?;
257+ enqueue_next_job ( & mut * conn, & mut index) . await ?;
250258 Ok ( ( ) )
251259}
252260
@@ -455,14 +463,12 @@ mod tests {
455463 let jobs = create_benchmark_jobs ( & request) . unwrap ( ) ;
456464
457465 let create_job = |profile : Profile | -> BenchmarkJob {
458- BenchmarkJob :: new (
466+ BenchmarkJob :: create_queued (
459467 Target :: X86_64UnknownLinuxGnu ,
460468 CodegenBackend :: Llvm ,
461469 profile,
462470 request. tag ( ) . unwrap ( ) ,
463471 0u32 ,
464- Utc :: now ( ) ,
465- BenchmarkJobStatus :: Queued ,
466472 )
467473 } ;
468474
0 commit comments