@@ -6,9 +6,7 @@ use crate::job_queue::utils::{parse_release_string, ExtractIf};
66use crate :: load:: { partition_in_place, SiteCtxt } ;
77use chrono:: Utc ;
88use collector:: benchmark_set:: benchmark_set_count;
9- use database:: {
10- BenchmarkJob , BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , Target ,
11- } ;
9+ use database:: { BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , Target } ;
1210use hashbrown:: HashSet ;
1311use parking_lot:: RwLock ;
1412use tokio:: time:: { self , Duration } ;
@@ -178,17 +176,19 @@ pub async fn build_queue(
178176}
179177
180178/// From a benchmark_request create all the required jobs
181- pub fn create_benchmark_jobs (
179+ pub async fn create_benchmark_jobs (
180+ conn : & mut dyn database:: pool:: Connection ,
182181 benchmark_request : & BenchmarkRequest ,
183- ) -> anyhow:: Result < Vec < BenchmarkJob > > {
182+ ) -> anyhow:: Result < ( ) > {
183+ let mut tx = conn. transaction ( ) . await ;
184184 anyhow:: ensure!(
185185 benchmark_request. tag( ) . is_some( ) ,
186186 "Benchmark request has no tag"
187187 ) ;
188188
189189 let backends = benchmark_request. backends ( ) ?;
190190 let profiles = benchmark_request. profiles ( ) ?;
191- let mut jobs = vec ! [ ] ;
191+ let request_tag = benchmark_request . tag ( ) . unwrap ( ) ;
192192
193193 // Target x benchmark_set x backend x profile -> BenchmarkJob
194194 for target in Target :: all ( ) {
@@ -197,20 +197,40 @@ pub fn create_benchmark_jobs(
197197 ) {
198198 for backend in backends. iter ( ) {
199199 for profile in profiles. iter ( ) {
200- let job = BenchmarkJob :: create_queued (
201- target,
202- * backend,
203- * profile,
204- benchmark_request. tag ( ) . unwrap ( ) ,
205- benchmark_set as u32 ,
206- ) ;
207- jobs. push ( job) ;
200+ tx. conn ( )
201+ . enqueue_benchmark_job (
202+ request_tag,
203+ & target,
204+ backend,
205+ profile,
206+ benchmark_set as u32 ,
207+ )
208+ . await ?;
209+ // If there is a parent, we create a job for it to. The
210+ // database will ignore it if there is already a job there.
211+ // If the parent job has been deleted from the database
212+ // but was already benchmarked then the collector will ignore
213+ // it as it will see it already has results.
214+ if let Some ( parent_sha) = benchmark_request. parent_sha ( ) {
215+ tx. conn ( )
216+ . enqueue_benchmark_job (
217+ parent_sha,
218+ & target,
219+ backend,
220+ profile,
221+ benchmark_set as u32 ,
222+ )
223+ . await ?;
224+ }
208225 }
209226 }
210227 }
211228 }
212229
213- Ok ( jobs)
230+ tx. conn ( )
231+ . update_benchmark_request_status ( request_tag, BenchmarkRequestStatus :: InProgress )
232+ . await ?;
233+ Ok ( ( ) )
214234}
215235
216236/// Enqueue the job into the job_queue
@@ -219,30 +239,12 @@ async fn enqueue_next_job(
219239 index : & mut BenchmarkRequestIndex ,
220240) -> anyhow:: Result < ( ) > {
221241 let queue = build_queue ( conn, index) . await ?;
222- let mut tx = conn. transaction ( ) . await ;
223242 for request in queue {
224243 if request. status ( ) != BenchmarkRequestStatus :: InProgress {
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 ?;
235- }
236- tx. conn ( )
237- . update_benchmark_request_status (
238- request. tag ( ) . unwrap ( ) ,
239- BenchmarkRequestStatus :: InProgress ,
240- )
241- . await ?;
244+ create_benchmark_jobs ( conn, & request) . await ?;
242245 break ;
243246 }
244247 }
245- tx. commit ( ) . await ?;
246248 Ok ( ( ) )
247249}
248250
@@ -282,7 +284,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
282284mod tests {
283285 use super :: * ;
284286 use chrono:: { Datelike , Duration , TimeZone , Utc } ;
285- use database:: { tests:: run_postgres_test, CodegenBackend , Profile } ;
287+ use database:: tests:: run_postgres_test;
286288
287289 fn days_ago ( day_str : & str ) -> chrono:: DateTime < Utc > {
288290 // Walk backwards until the first non-digit, then slice
@@ -346,18 +348,6 @@ mod tests {
346348 assert_eq ! ( queue_shas, expected)
347349 }
348350
349- fn benchmark_jobs_match ( jobs : & [ BenchmarkJob ] , expected_jobs : & [ BenchmarkJob ] ) {
350- assert_eq ! ( jobs. len( ) , expected_jobs. len( ) ) ;
351- for ( job, expected) in std:: iter:: zip ( jobs, expected_jobs) {
352- assert_eq ! ( job. target( ) , expected. target( ) ) ;
353- assert_eq ! ( job. backend( ) , expected. backend( ) ) ;
354- assert_eq ! ( job. profile( ) , expected. profile( ) ) ;
355- assert_eq ! ( job. benchmark_set( ) , expected. benchmark_set( ) ) ;
356- assert_eq ! ( job. request_tag( ) , expected. request_tag( ) ) ;
357- assert_eq ! ( job. status( ) , expected. status( ) ) ;
358- }
359- }
360-
361351 #[ tokio:: test]
362352 async fn queue_ordering ( ) {
363353 run_postgres_test ( |ctx| async {
@@ -456,30 +446,4 @@ mod tests {
456446 } )
457447 . await ;
458448 }
459-
460- #[ test]
461- fn create_benchmark_jobs_default ( ) {
462- let request = create_master ( "bar" , "parent1" , 10 , "days2" ) ;
463- let jobs = create_benchmark_jobs ( & request) . unwrap ( ) ;
464-
465- let create_job = |profile : Profile | -> BenchmarkJob {
466- BenchmarkJob :: create_queued (
467- Target :: X86_64UnknownLinuxGnu ,
468- CodegenBackend :: Llvm ,
469- profile,
470- request. tag ( ) . unwrap ( ) ,
471- 0u32 ,
472- )
473- } ;
474-
475- benchmark_jobs_match (
476- & vec ! [
477- create_job( Profile :: Check ) ,
478- create_job( Profile :: Debug ) ,
479- create_job( Profile :: Doc ) ,
480- create_job( Profile :: Opt ) ,
481- ] ,
482- & jobs,
483- ) ;
484- }
485449}
0 commit comments