Skip to content

Commit ba205ec

Browse files
committed
don't report yank errors for releases that have a build queued
1 parent a9b3536 commit ba205ec

File tree

1 file changed

+84
-35
lines changed

1 file changed

+84
-35
lines changed

src/build_queue.rs

Lines changed: 84 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::utils::{get_config, get_crate_priority, report_error, set_config, Con
77
use crate::{Config, Index, Metrics, RustwideBuilder};
88
use anyhow::Context;
99

10-
use tracing::{debug, error, info, instrument, warn};
10+
use tracing::{debug, error, info, warn};
1111

1212
use std::collections::HashMap;
1313
use std::sync::Arc;
@@ -147,6 +147,23 @@ impl BuildQueue {
147147
.collect())
148148
}
149149

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+
150167
pub(crate) fn process_next_crate(
151168
&self,
152169
f: impl FnOnce(&QueuedCrate) -> Result<()>,
@@ -264,37 +281,6 @@ fn retry<T>(mut f: impl FnMut() -> Result<T>, max_attempts: u32) -> Result<T> {
264281
unreachable!()
265282
}
266283

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-
298284
/// Index methods.
299285
impl BuildQueue {
300286
/// Updates registry index repository and adds new crates into build queue.
@@ -356,9 +342,10 @@ impl BuildQueue {
356342
let yanked = change.yanked();
357343
let unyanked = change.unyanked();
358344
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(
362349
&mut conn,
363350
release.name.as_str(),
364351
release.version.as_str(),
@@ -385,6 +372,50 @@ impl BuildQueue {
385372
Ok(crates_added)
386373
}
387374

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+
388419
/// Builds the top package from the queue. Returns whether there was a package in the queue.
389420
///
390421
/// Note that this will return `Ok(true)` even if the package failed to build.
@@ -495,6 +526,24 @@ mod tests {
495526
})
496527
}
497528

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+
498547
#[test]
499548
fn test_add_and_process_crates() {
500549
const MAX_ATTEMPTS: u16 = 3;

0 commit comments

Comments
 (0)