@@ -6,9 +6,7 @@ use crate::job_queue::utils::{parse_release_string, ExtractIf};
6
6
use crate :: load:: { partition_in_place, SiteCtxt } ;
7
7
use chrono:: Utc ;
8
8
use collector:: benchmark_set:: benchmark_set_count;
9
- use database:: {
10
- BenchmarkJob , BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , Target ,
11
- } ;
9
+ use database:: { BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , Target } ;
12
10
use hashbrown:: HashSet ;
13
11
use parking_lot:: RwLock ;
14
12
use tokio:: time:: { self , Duration } ;
@@ -178,17 +176,19 @@ pub async fn build_queue(
178
176
}
179
177
180
178
/// 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 ,
182
181
benchmark_request : & BenchmarkRequest ,
183
- ) -> anyhow:: Result < Vec < BenchmarkJob > > {
182
+ ) -> anyhow:: Result < ( ) > {
183
+ let mut tx = conn. transaction ( ) . await ;
184
184
anyhow:: ensure!(
185
185
benchmark_request. tag( ) . is_some( ) ,
186
186
"Benchmark request has no tag"
187
187
) ;
188
188
189
189
let backends = benchmark_request. backends ( ) ?;
190
190
let profiles = benchmark_request. profiles ( ) ?;
191
- let mut jobs = vec ! [ ] ;
191
+ let request_tag = benchmark_request . tag ( ) . unwrap ( ) ;
192
192
193
193
// Target x benchmark_set x backend x profile -> BenchmarkJob
194
194
for target in Target :: all ( ) {
@@ -197,20 +197,40 @@ pub fn create_benchmark_jobs(
197
197
) {
198
198
for backend in backends. iter ( ) {
199
199
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
+ }
208
225
}
209
226
}
210
227
}
211
228
}
212
229
213
- Ok ( jobs)
230
+ tx. conn ( )
231
+ . update_benchmark_request_status ( request_tag, BenchmarkRequestStatus :: InProgress )
232
+ . await ?;
233
+ Ok ( ( ) )
214
234
}
215
235
216
236
/// Enqueue the job into the job_queue
@@ -219,30 +239,12 @@ async fn enqueue_next_job(
219
239
index : & mut BenchmarkRequestIndex ,
220
240
) -> anyhow:: Result < ( ) > {
221
241
let queue = build_queue ( conn, index) . await ?;
222
- let mut tx = conn. transaction ( ) . await ;
223
242
for request in queue {
224
243
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 ?;
242
245
break ;
243
246
}
244
247
}
245
- tx. commit ( ) . await ?;
246
248
Ok ( ( ) )
247
249
}
248
250
@@ -282,7 +284,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
282
284
mod tests {
283
285
use super :: * ;
284
286
use chrono:: { Datelike , Duration , TimeZone , Utc } ;
285
- use database:: { tests:: run_postgres_test, CodegenBackend , Profile } ;
287
+ use database:: tests:: run_postgres_test;
286
288
287
289
fn days_ago ( day_str : & str ) -> chrono:: DateTime < Utc > {
288
290
// Walk backwards until the first non-digit, then slice
@@ -346,18 +348,6 @@ mod tests {
346
348
assert_eq ! ( queue_shas, expected)
347
349
}
348
350
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
-
361
351
#[ tokio:: test]
362
352
async fn queue_ordering ( ) {
363
353
run_postgres_test ( |ctx| async {
@@ -456,30 +446,4 @@ mod tests {
456
446
} )
457
447
. await ;
458
448
}
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
- }
485
449
}
0 commit comments