@@ -7,7 +7,7 @@ use crate::utils::{get_config, get_crate_priority, report_error, set_config, Con
7
7
use crate :: { Config , Index , Metrics , RustwideBuilder } ;
8
8
use anyhow:: Context ;
9
9
10
- use tracing:: { debug, error, info, instrument , warn} ;
10
+ use tracing:: { debug, error, info, warn} ;
11
11
12
12
use std:: collections:: HashMap ;
13
13
use std:: sync:: Arc ;
@@ -147,6 +147,23 @@ impl BuildQueue {
147
147
. collect ( ) )
148
148
}
149
149
150
+ fn has_build_queued ( & self , name : & str , version : & str ) -> Result < bool > {
151
+ Ok ( self
152
+ . db
153
+ . get ( ) ?
154
+ . query_opt (
155
+ "SELECT id
156
+ FROM queue
157
+ WHERE
158
+ attempt < $1 AND
159
+ name = $2 AND
160
+ version = $3
161
+ " ,
162
+ & [ & self . max_attempts , & name, & version] ,
163
+ ) ?
164
+ . is_some ( ) )
165
+ }
166
+
150
167
pub ( crate ) fn process_next_crate (
151
168
& self ,
152
169
f : impl FnOnce ( & QueuedCrate ) -> Result < ( ) > ,
@@ -264,37 +281,6 @@ fn retry<T>(mut f: impl FnMut() -> Result<T>, max_attempts: u32) -> Result<T> {
264
281
unreachable ! ( )
265
282
}
266
283
267
- #[ instrument( skip( conn) ) ]
268
- fn set_yanked ( conn : & mut postgres:: Client , name : & str , version : & str , yanked : bool ) {
269
- let activity = if yanked { "yanked" } else { "unyanked" } ;
270
-
271
- match conn
272
- . execute (
273
- "UPDATE releases
274
- SET yanked = $3
275
- FROM crates
276
- WHERE crates.id = releases.crate_id
277
- AND name = $1
278
- AND version = $2
279
- " ,
280
- & [ & name, & version, & yanked] ,
281
- )
282
- . with_context ( || format ! ( "error while setting {}-{} to {}" , name, version, activity) )
283
- {
284
- Ok ( rows) => {
285
- if rows != 1 {
286
- error ! (
287
- "tried to yank or unyank non-existing release: {} {}" ,
288
- name, version
289
- ) ;
290
- } else {
291
- debug ! ( "{}-{} {}" , name, version, activity) ;
292
- }
293
- }
294
- Err ( err) => report_error ( & err) ,
295
- }
296
- }
297
-
298
284
/// Index methods.
299
285
impl BuildQueue {
300
286
/// Updates registry index repository and adds new crates into build queue.
@@ -356,9 +342,10 @@ impl BuildQueue {
356
342
let yanked = change. yanked ( ) ;
357
343
let unyanked = change. unyanked ( ) ;
358
344
if let Some ( release) = yanked. or ( unyanked) {
359
- // FIXME: delay yanks of crates that have not yet finished building
360
- // https://github.com/rust-lang/docs.rs/issues/1934
361
- set_yanked (
345
+ // FIXME: https://github.com/rust-lang/docs.rs/issues/1934
346
+ // we sometimes have inconsistencies between our yank-state and
347
+ // the crates.io yank state, and we don't know why yet.
348
+ self . set_yanked (
362
349
& mut conn,
363
350
release. name . as_str ( ) ,
364
351
release. version . as_str ( ) ,
@@ -385,6 +372,50 @@ impl BuildQueue {
385
372
Ok ( crates_added)
386
373
}
387
374
375
+ fn set_yanked ( & self , conn : & mut postgres:: Client , name : & str , version : & str , yanked : bool ) {
376
+ let activity = if yanked { "yanked" } else { "unyanked" } ;
377
+
378
+ match conn
379
+ . execute (
380
+ "UPDATE releases
381
+ SET yanked = $3
382
+ FROM crates
383
+ WHERE crates.id = releases.crate_id
384
+ AND name = $1
385
+ AND version = $2
386
+ " ,
387
+ & [ & name, & version, & yanked] ,
388
+ )
389
+ . with_context ( || format ! ( "error while setting {}-{} to {}" , name, version, activity) )
390
+ {
391
+ Ok ( rows) => {
392
+ if rows != 1 {
393
+ match self
394
+ . has_build_queued ( name, version)
395
+ . context ( "error trying to fetch build queue" )
396
+ {
397
+ Ok ( false ) => {
398
+ // the rustwide builder will fetch the current yank state from
399
+ // crates.io, so and missed update here will be fixed after the
400
+ // build is finished.
401
+ error ! (
402
+ "tried to yank or unyank non-existing release: {} {}" ,
403
+ name, version
404
+ ) ;
405
+ }
406
+ Ok ( true ) => { }
407
+ Err ( err) => {
408
+ report_error ( & err) ;
409
+ }
410
+ }
411
+ } else {
412
+ debug ! ( "{}-{} {}" , name, version, activity) ;
413
+ }
414
+ }
415
+ Err ( err) => report_error ( & err) ,
416
+ }
417
+ }
418
+
388
419
/// Builds the top package from the queue. Returns whether there was a package in the queue.
389
420
///
390
421
/// Note that this will return `Ok(true)` even if the package failed to build.
@@ -495,6 +526,24 @@ mod tests {
495
526
} )
496
527
}
497
528
529
+ #[ test]
530
+ fn test_has_build_queued ( ) {
531
+ crate :: test:: wrapper ( |env| {
532
+ let queue = env. build_queue ( ) ;
533
+
534
+ queue. add_crate ( "dummy" , "0.1.1" , 0 , None ) ?;
535
+ assert ! ( queue. has_build_queued( "dummy" , "0.1.1" ) ?) ;
536
+
537
+ env. db ( )
538
+ . conn ( )
539
+ . execute ( "UPDATE queue SET attempt = 6" , & [ ] ) ?;
540
+
541
+ assert ! ( !queue. has_build_queued( "dummy" , "0.1.1" ) ?) ;
542
+
543
+ Ok ( ( ) )
544
+ } )
545
+ }
546
+
498
547
#[ test]
499
548
fn test_add_and_process_crates ( ) {
500
549
const MAX_ATTEMPTS : u16 = 3 ;
0 commit comments