11mod utils;
22
3+ use crate :: github:: comparison_summary:: post_comparison_comment;
34use crate :: job_queue:: utils:: { parse_release_string, ExtractIf } ;
45use crate :: load:: { partition_in_place, SiteCtxt } ;
56use chrono:: Utc ;
67use collector:: benchmark_set:: benchmark_set_count;
78use database:: {
8- BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , PendingBenchmarkRequests ,
9- Target ,
9+ BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkRequestType , Date ,
10+ PendingBenchmarkRequests , QueuedCommit , Target ,
1011} ;
1112use parking_lot:: RwLock ;
1213use std:: { str:: FromStr , sync:: Arc } ;
@@ -262,16 +263,20 @@ pub async fn enqueue_benchmark_request(
262263/// If there is a request that has artifacts ready, and nothing is currently in-progress,
263264/// it will be enqueued.
264265/// If there is a request whose jobs have all completed, it will be marked as completed.
266+ ///
267+ /// Returns benchmark requests that were completed.
265268async fn process_benchmark_requests (
266269 conn : & mut dyn database:: pool:: Connection ,
267- ) -> anyhow:: Result < ( ) > {
270+ ) -> anyhow:: Result < Vec < BenchmarkRequest > > {
268271 let queue = build_queue ( conn) . await ?;
269272
273+ let mut completed = vec ! [ ] ;
270274 for request in queue {
271275 match request. status ( ) {
272276 BenchmarkRequestStatus :: InProgress => {
273277 let tag = request. tag ( ) . expect ( "In progress request without a tag" ) ;
274278 if conn. maybe_mark_benchmark_request_as_completed ( tag) . await ? {
279+ completed. push ( request) ;
275280 continue ;
276281 }
277282 break ;
@@ -286,30 +291,81 @@ async fn process_benchmark_requests(
286291 }
287292 }
288293 }
289- Ok ( ( ) )
294+ Ok ( completed )
290295}
291296
292297/// 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 ;
295300
296- let index = site_ctxt . known_benchmark_requests . load ( ) ;
301+ let index = ctxt . known_benchmark_requests . load ( ) ;
297302
298303 let mut requests_inserted = false ;
299304 // 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 ?;
301306 // Put the releases into the `benchmark_requests` queue
302307 requests_inserted |= create_benchmark_request_releases ( & * conn, & index) . await ?;
303308 // 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 ?;
305310
306311 // If some change happened, reload the benchmark request index
307312 if requests_inserted {
308- site_ctxt
309- . known_benchmark_requests
313+ ctxt. known_benchmark_requests
310314 . store ( Arc :: new ( conn. load_benchmark_request_index ( ) . await ?) ) ;
311315 }
312316
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+
313369 Ok ( ( ) )
314370}
315371
0 commit comments