@@ -13,19 +13,26 @@ use parking_lot::RwLock;
13
13
use std:: { str:: FromStr , sync:: Arc } ;
14
14
use tokio:: time:: { self , Duration , MissedTickBehavior } ;
15
15
16
- pub fn run_new_queue ( ) -> bool {
17
- std:: env:: var ( "RUN_CRON " )
16
+ pub fn is_job_queue_enabled ( ) -> bool {
17
+ std:: env:: var ( "USE_JOB_QUEUE " )
18
18
. ok ( )
19
19
. and_then ( |x| x. parse ( ) . ok ( ) )
20
- . unwrap_or ( false )
20
+ . unwrap_or ( true )
21
+ }
22
+
23
+ /// rust-lang/rust PR that will be used for testing the job queue.
24
+ const TEST_PR_FOR_JOB_QUEUE : u32 = 147039 ;
25
+
26
+ pub fn should_use_job_queue ( pr : u32 ) -> bool {
27
+ is_job_queue_enabled ( ) && pr == TEST_PR_FOR_JOB_QUEUE
21
28
}
22
29
23
30
/// Store the latest master commits or do nothing if all of them are
24
31
/// already in the database.
25
32
/// Returns `true` if at least one benchmark request was inserted.
26
33
async fn create_benchmark_request_master_commits (
27
34
ctxt : & SiteCtxt ,
28
- conn : & dyn database:: pool:: Connection ,
35
+ _conn : & dyn database:: pool:: Connection ,
29
36
index : & BenchmarkRequestIndex ,
30
37
) -> anyhow:: Result < bool > {
31
38
let now = Utc :: now ( ) ;
@@ -40,23 +47,26 @@ async fn create_benchmark_request_master_commits(
40
47
// TODO; delete at some point in the future
41
48
let cutoff: chrono:: DateTime < Utc > = chrono:: DateTime :: from_str ( "2025-08-27T00:00:00.000Z" ) ?;
42
49
43
- let mut inserted = false ;
50
+ let inserted = false ;
44
51
for master_commit in master_commits {
45
52
// We don't want to add masses of obsolete data
46
53
if master_commit. time >= cutoff && !index. contains_tag ( & master_commit. sha ) {
47
- let pr = master_commit. pr . unwrap_or ( 0 ) ;
48
- let benchmark = BenchmarkRequest :: create_master (
49
- & master_commit. sha ,
50
- & master_commit. parent_sha ,
51
- pr,
52
- master_commit. time ,
53
- ) ;
54
- log:: info!( "Inserting master benchmark request {benchmark:?}" ) ;
55
- if let Err ( error) = conn. insert_benchmark_request ( & benchmark) . await {
56
- log:: error!( "Failed to insert master benchmark request: {error:?}" ) ;
57
- } else {
58
- inserted = true ;
59
- }
54
+ // let pr = master_commit.pr.unwrap_or(0);
55
+ // let benchmark = BenchmarkRequest::create_master(
56
+ // &master_commit.sha,
57
+ // &master_commit.parent_sha,
58
+ // pr,
59
+ // master_commit.time,
60
+ // );
61
+ // log::info!("Inserting master benchmark request {benchmark:?}");
62
+
63
+ // Do not create benchmark requests on production, to allow running in parallel with
64
+ // the old system.
65
+ // if let Err(error) = conn.insert_benchmark_request(&benchmark).await {
66
+ // log::error!("Failed to insert master benchmark request: {error:?}");
67
+ // } else {
68
+ // inserted = true;
69
+ // }
60
70
}
61
71
}
62
72
Ok ( inserted)
@@ -66,7 +76,7 @@ async fn create_benchmark_request_master_commits(
66
76
/// already in the database
67
77
/// Returns `true` if at least one benchmark request was inserted.
68
78
async fn create_benchmark_request_releases (
69
- conn : & dyn database:: pool:: Connection ,
79
+ _conn : & dyn database:: pool:: Connection ,
70
80
index : & BenchmarkRequestIndex ,
71
81
) -> anyhow:: Result < bool > {
72
82
let releases: String = reqwest:: get ( "https://static.rust-lang.org/manifests.txt" )
@@ -82,16 +92,19 @@ async fn create_benchmark_request_releases(
82
92
. filter_map ( parse_release_string)
83
93
. take ( 20 ) ;
84
94
85
- let mut inserted = false ;
95
+ let inserted = false ;
86
96
for ( name, commit_date) in releases {
87
97
if commit_date >= cutoff && !index. contains_tag ( & name) {
88
- let release_request = BenchmarkRequest :: create_release ( & name, commit_date) ;
89
- log:: info!( "Inserting release benchmark request {release_request:?}" ) ;
90
- if let Err ( error) = conn. insert_benchmark_request ( & release_request) . await {
91
- log:: error!( "Failed to insert release benchmark request: {error}" ) ;
92
- } else {
93
- inserted = true ;
94
- }
98
+ // let release_request = BenchmarkRequest::create_release(&name, commit_date);
99
+ // log::info!("Inserting release benchmark request {release_request:?}");
100
+
101
+ // Do not create benchmark requests on production, to allow running in parallel with
102
+ // the old system.
103
+ // if let Err(error) = conn.insert_benchmark_request(&release_request).await {
104
+ // log::error!("Failed to insert release benchmark request: {error}");
105
+ // } else {
106
+ // inserted = true;
107
+ // }
95
108
}
96
109
}
97
110
Ok ( inserted)
@@ -204,20 +217,20 @@ pub async fn build_queue(
204
217
/// This is performed atomically, in a transaction.
205
218
pub async fn enqueue_benchmark_request (
206
219
conn : & mut dyn database:: pool:: Connection ,
207
- benchmark_request : & BenchmarkRequest ,
220
+ request : & BenchmarkRequest ,
208
221
) -> anyhow:: Result < ( ) > {
209
222
let mut tx = conn. transaction ( ) . await ;
210
223
211
- let Some ( request_tag) = benchmark_request . tag ( ) else {
212
- panic ! ( "Benchmark request {benchmark_request :?} has no tag" ) ;
224
+ let Some ( request_tag) = request . tag ( ) else {
225
+ panic ! ( "Benchmark request {request :?} has no tag" ) ;
213
226
} ;
214
227
215
- log:: info!( "Enqueuing jobs for request {benchmark_request :?}" ) ;
228
+ log:: info!( "Enqueuing jobs for request {request :?}" ) ;
216
229
217
- let backends = benchmark_request . backends ( ) ?;
218
- let profiles = benchmark_request . profiles ( ) ?;
230
+ let backends = request . backends ( ) ?;
231
+ let profiles = request . profiles ( ) ?;
219
232
// Prevent the error from spamming the logs
220
- let mut has_emitted_parent_sha_error = false ;
233
+ // let mut has_emitted_parent_sha_error = false;
221
234
222
235
// Target x benchmark_set x backend x profile -> BenchmarkJob
223
236
for target in Target :: all ( ) {
@@ -238,32 +251,36 @@ pub async fn enqueue_benchmark_request(
238
251
// If the parent job has been deleted from the database
239
252
// but was already benchmarked then the collector will ignore
240
253
// it as it will see it already has results.
241
- if let Some ( parent_sha) = benchmark_request. parent_sha ( ) {
242
- let ( is_foreign_key_violation, result) = tx
243
- . conn ( )
244
- . enqueue_parent_benchmark_job (
245
- parent_sha,
246
- target,
247
- backend,
248
- profile,
249
- benchmark_set as u32 ,
250
- )
251
- . await ;
252
-
253
- // At some point in time the parent_sha may not refer
254
- // to a `benchmark_request` and we want to be able to
255
- // see that error.
256
- if let Err ( e) = result {
257
- if is_foreign_key_violation && !has_emitted_parent_sha_error {
258
- log:: error!( "Failed to create job for parent sha {e:?}" ) ;
259
- has_emitted_parent_sha_error = true ;
260
- } else if has_emitted_parent_sha_error && is_foreign_key_violation {
261
- continue ;
262
- } else {
263
- return Err ( e) ;
264
- }
265
- }
266
- }
254
+
255
+ // Do not enqueue parent jobs to allow parallel execution with the old system
256
+ // If the parent artifact wouldn't be benchmarked yet, we would benchmark the
257
+ // parent with the new system.
258
+ // if let Some(parent_sha) = request.parent_sha() {
259
+ // let (is_foreign_key_violation, result) = tx
260
+ // .conn()
261
+ // .enqueue_parent_benchmark_job(
262
+ // parent_sha,
263
+ // target,
264
+ // backend,
265
+ // profile,
266
+ // benchmark_set as u32,
267
+ // )
268
+ // .await;
269
+ //
270
+ // // At some point in time the parent_sha may not refer
271
+ // // to a `benchmark_request` and we want to be able to
272
+ // // see that error.
273
+ // if let Err(e) = result {
274
+ // if is_foreign_key_violation && !has_emitted_parent_sha_error {
275
+ // log::error!("Failed to create job for parent sha {e:?}");
276
+ // has_emitted_parent_sha_error = true;
277
+ // } else if has_emitted_parent_sha_error && is_foreign_key_violation {
278
+ // continue;
279
+ // } else {
280
+ // return Err(e);
281
+ // }
282
+ // }
283
+ // }
267
284
}
268
285
}
269
286
}
@@ -287,12 +304,15 @@ async fn process_benchmark_requests(
287
304
) -> anyhow:: Result < Vec < BenchmarkRequest > > {
288
305
let queue = build_queue ( conn) . await ?;
289
306
307
+ log:: debug!( "Current queue: {queue:?}" ) ;
308
+
290
309
let mut completed = vec ! [ ] ;
291
310
for request in queue {
292
311
match request. status ( ) {
293
312
BenchmarkRequestStatus :: InProgress => {
294
313
let tag = request. tag ( ) . expect ( "In progress request without a tag" ) ;
295
314
if conn. maybe_mark_benchmark_request_as_completed ( tag) . await ? {
315
+ log:: info!( "Request {tag} marked as completed" ) ;
296
316
completed. push ( request) ;
297
317
continue ;
298
318
}
@@ -311,8 +331,9 @@ async fn process_benchmark_requests(
311
331
Ok ( completed)
312
332
}
313
333
314
- /// For queueing jobs, add the jobs you want to queue to this function
315
- async fn cron_enqueue_jobs ( ctxt : & SiteCtxt ) -> anyhow:: Result < ( ) > {
334
+ /// Creates new benchmark requests, enqueues jobs for ready benchmark requests and
335
+ /// finishes completed benchmark requests.
336
+ async fn perform_queue_tick ( ctxt : & SiteCtxt ) -> anyhow:: Result < ( ) > {
316
337
let mut conn = ctxt. conn ( ) . await ;
317
338
318
339
let index = ctxt. known_benchmark_requests . load ( ) ;
@@ -387,7 +408,10 @@ async fn cron_enqueue_jobs(ctxt: &SiteCtxt) -> anyhow::Result<()> {
387
408
}
388
409
389
410
/// Entry point for the cron job that manages the benchmark request and job queue.
390
- pub async fn cron_main ( site_ctxt : Arc < RwLock < Option < Arc < SiteCtxt > > > > , run_interval : Duration ) {
411
+ pub async fn create_queue_process (
412
+ site_ctxt : Arc < RwLock < Option < Arc < SiteCtxt > > > > ,
413
+ run_interval : Duration ,
414
+ ) {
391
415
let mut interval = time:: interval ( run_interval) ;
392
416
interval. set_missed_tick_behavior ( MissedTickBehavior :: Delay ) ;
393
417
@@ -398,7 +422,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, run_interv
398
422
let guard = ctxt. read ( ) ;
399
423
guard. as_ref ( ) . cloned ( )
400
424
} {
401
- match cron_enqueue_jobs ( & ctxt_clone) . await {
425
+ match perform_queue_tick ( & ctxt_clone) . await {
402
426
Ok ( _) => log:: info!( "Cron job finished" ) ,
403
427
Err ( e) => log:: error!( "Cron job failed to execute: {e:?}" ) ,
404
428
}
0 commit comments