1
1
mod utils;
2
2
3
+ use crate :: github:: comparison_summary:: post_comparison_comment;
3
4
use crate :: job_queue:: utils:: { parse_release_string, ExtractIf } ;
4
5
use crate :: load:: { partition_in_place, SiteCtxt } ;
5
6
use chrono:: Utc ;
6
7
use collector:: benchmark_set:: benchmark_set_count;
7
8
use database:: {
8
- BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , PendingBenchmarkRequests ,
9
- Target ,
9
+ BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkRequestType , Date ,
10
+ PendingBenchmarkRequests , QueuedCommit , Target ,
10
11
} ;
11
12
use parking_lot:: RwLock ;
12
13
use std:: { str:: FromStr , sync:: Arc } ;
@@ -262,16 +263,20 @@ pub async fn enqueue_benchmark_request(
262
263
/// If there is a request that has artifacts ready, and nothing is currently in-progress,
263
264
/// it will be enqueued.
264
265
/// If there is a request whose jobs have all completed, it will be marked as completed.
266
+ ///
267
+ /// Returns benchmark requests that were completed.
265
268
async fn process_benchmark_requests (
266
269
conn : & mut dyn database:: pool:: Connection ,
267
- ) -> anyhow:: Result < ( ) > {
270
+ ) -> anyhow:: Result < Vec < BenchmarkRequest > > {
268
271
let queue = build_queue ( conn) . await ?;
269
272
273
+ let mut completed = vec ! [ ] ;
270
274
for request in queue {
271
275
match request. status ( ) {
272
276
BenchmarkRequestStatus :: InProgress => {
273
277
let tag = request. tag ( ) . expect ( "In progress request without a tag" ) ;
274
278
if conn. maybe_mark_benchmark_request_as_completed ( tag) . await ? {
279
+ completed. push ( request) ;
275
280
continue ;
276
281
}
277
282
break ;
@@ -286,30 +291,81 @@ async fn process_benchmark_requests(
286
291
}
287
292
}
288
293
}
289
- Ok ( ( ) )
294
+ Ok ( completed )
290
295
}
291
296
292
297
/// For queueing jobs, add the jobs you want to queue to this function
293
- async fn cron_enqueue_jobs ( site_ctxt : & SiteCtxt ) -> anyhow:: Result < ( ) > {
294
- let mut conn = site_ctxt . conn ( ) . await ;
298
+ async fn cron_enqueue_jobs ( ctxt : & SiteCtxt ) -> anyhow:: Result < ( ) > {
299
+ let mut conn = ctxt . conn ( ) . await ;
295
300
296
- let index = site_ctxt . known_benchmark_requests . load ( ) ;
301
+ let index = ctxt . known_benchmark_requests . load ( ) ;
297
302
298
303
let mut requests_inserted = false ;
299
304
// Put the master commits into the `benchmark_requests` queue
300
- requests_inserted |= create_benchmark_request_master_commits ( site_ctxt , & * conn, & index) . await ?;
305
+ requests_inserted |= create_benchmark_request_master_commits ( ctxt , & * conn, & index) . await ?;
301
306
// Put the releases into the `benchmark_requests` queue
302
307
requests_inserted |= create_benchmark_request_releases ( & * conn, & index) . await ?;
303
308
// Enqueue waiting requests and try to complete in-progress ones
304
- process_benchmark_requests ( & mut * conn) . await ?;
309
+ let completed_reqs = process_benchmark_requests ( & mut * conn) . await ?;
305
310
306
311
// If some change happened, reload the benchmark request index
307
312
if requests_inserted {
308
- site_ctxt
309
- . known_benchmark_requests
313
+ ctxt. known_benchmark_requests
310
314
. store ( Arc :: new ( conn. load_benchmark_request_index ( ) . await ?) ) ;
311
315
}
312
316
317
+ // Send a comment to GitHub for completed requests and reload the DB index
318
+ if !completed_reqs. is_empty ( ) {
319
+ let index = database:: Index :: load ( & mut * conn) . await ;
320
+ log:: info!( "index has {} commits" , index. commits( ) . len( ) ) ;
321
+ ctxt. index . store ( Arc :: new ( index) ) ;
322
+
323
+ // Refresh the landing page
324
+ ctxt. landing_page . store ( Arc :: new ( None ) ) ;
325
+
326
+ // Send comments to GitHub
327
+ for request in completed_reqs {
328
+ let ( is_master, pr, sha, parent_sha) = match request. commit_type ( ) {
329
+ BenchmarkRequestType :: Try {
330
+ pr,
331
+ parent_sha,
332
+ sha,
333
+ } => (
334
+ false ,
335
+ * pr,
336
+ sha. clone ( ) . expect ( "Completed try commit without a SHA" ) ,
337
+ parent_sha
338
+ . clone ( )
339
+ . expect ( "Completed try commit without a parent SHA" ) ,
340
+ ) ,
341
+ BenchmarkRequestType :: Master {
342
+ pr,
343
+ sha,
344
+ parent_sha,
345
+ } => ( true , * pr, sha. clone ( ) , parent_sha. clone ( ) ) ,
346
+ BenchmarkRequestType :: Release { .. } => continue ,
347
+ } ;
348
+ let commit = QueuedCommit {
349
+ pr,
350
+ sha,
351
+ parent_sha,
352
+ include : None ,
353
+ exclude : None ,
354
+ runs : None ,
355
+ commit_date : request. commit_date ( ) . map ( Date ) ,
356
+ backends : Some (
357
+ request
358
+ . backends ( ) ?
359
+ . into_iter ( )
360
+ . map ( |b| b. as_str ( ) )
361
+ . collect :: < Vec < _ > > ( )
362
+ . join ( "," ) ,
363
+ ) ,
364
+ } ;
365
+ post_comparison_comment ( ctxt, commit, is_master) . await ?;
366
+ }
367
+ }
368
+
313
369
Ok ( ( ) )
314
370
}
315
371
0 commit comments