Skip to content

Commit b7a5f0f

Browse files
committed
refactor(queue): centralize definition for common priority levels
fix(queue): update query for faulty rustdoc builds to not assume build status implies anything on the rustdoc result, match on all releases of each crate rather than the latest only, and use the release_build_status table to simplify the query fix(logs): use fields for info! instead of string formatting docs(cratesfyi): clarify usage of command arguments for the new RebuildBrokenNightly command chore(tests): remove unneeded test environment config
1 parent 40fbec1 commit b7a5f0f

File tree

6 files changed

+151
-137
lines changed

6 files changed

+151
-137
lines changed

src/bin/cratesfyi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ enum QueueSubcommand {
272272
head: bool,
273273
},
274274

275-
/// Queue rebuilds for broken nightly versions of rustdoc
275+
/// Queue rebuilds for broken nightly versions of rustdoc, either for a single date (start) or a range (start inclusive, end exclusive)
276276
RebuildBrokenNightly {
277277
/// Start date of nightly builds to rebuild (inclusive)
278278
#[arg(name = "START", short = 's', long = "start")]

src/build_queue.rs

Lines changed: 123 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ use std::{collections::HashMap, sync::Arc};
1818
use tokio::runtime;
1919
use tracing::{debug, error, info, instrument, warn};
2020

21-
/// The static priority for background rebuilds.
22-
/// Used when queueing rebuilds, and when rendering them
23-
/// collapsed in the UI.
24-
/// For normal build priorities we use smaller values.
25-
pub(crate) const REBUILD_PRIORITY: i32 = 20;
26-
// TODO what value should we use here?
27-
pub(crate) const BROKEN_RUSTDOC_REBUILD_PRIORITY: i32 = 30;
21+
pub(crate) const PRIORITY_DEFAULT: i32 = 0;
22+
/// Used for workspaces to avoid blocking the queue (done through the cratesfyi CLI, not used in code)
23+
#[allow(dead_code)]
24+
pub(crate) const PRIORITY_DEPRIORITIZED: i32 = 1;
25+
/// Rebuilds triggered from crates.io, see issue #2442
26+
pub(crate) const PRIORITY_MANUAL_FROM_CRATES_IO: i32 = 5;
27+
/// Used for rebuilds queued through cratesfyi for crate versions failed due to a broken Rustdoc nightly version.
28+
/// Note: a broken rustdoc version does not necessarily imply a failed build.
29+
pub(crate) const PRIORITY_BROKEN_RUSTDOC: i32 = 10;
30+
/// Used by the synchronize cratesfyi command when queueing builds that are in the crates.io index but not in the database.
31+
pub(crate) const PRIORITY_CONSISTENCY_CHECK: i32 = 15;
32+
/// The static priority for background rebuilds, used when queueing rebuilds, and when rendering them collapsed in the UI.
33+
pub(crate) const PRIORITY_CONTINUOUS: i32 = 20;
2834

2935
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize)]
3036
pub(crate) struct QueuedCrate {
@@ -677,7 +683,7 @@ pub async fn queue_rebuilds(
677683
.pending_count_by_priority()
678684
.await?
679685
.iter()
680-
.filter_map(|(priority, count)| (*priority >= REBUILD_PRIORITY).then_some(count))
686+
.filter_map(|(priority, count)| (*priority >= PRIORITY_CONTINUOUS).then_some(count))
681687
.sum();
682688

683689
let rebuilds_to_queue = config
@@ -721,7 +727,7 @@ pub async fn queue_rebuilds(
721727
{
722728
info!("queueing rebuild for {} {}...", &row.name, &row.version);
723729
build_queue
724-
.add_crate(&row.name, &row.version, REBUILD_PRIORITY, None)
730+
.add_crate(&row.name, &row.version, PRIORITY_CONTINUOUS, None)
725731
.await?;
726732
}
727733
}
@@ -750,18 +756,16 @@ SELECT c.name,
750756
r.version AS "version: Version"
751757
FROM crates AS c
752758
JOIN releases AS r
753-
ON c.latest_version_id = r.id
754-
AND r.rustdoc_status = TRUE
755-
JOIN LATERAL (
756-
SELECT b.id,
757-
b.build_status,
758-
b.rustc_nightly_date,
759-
COALESCE(b.build_finished, b.build_started) AS last_build_attempt
760-
FROM builds AS b
761-
WHERE b.rid = r.id
762-
ORDER BY last_build_attempt DESC
763-
LIMIT 1
764-
) AS b ON b.build_status = 'failure' AND b.rustc_nightly_date >= $1 AND b.rustc_nightly_date < $2
759+
ON c.id = r.crate_id
760+
JOIN release_build_status AS rbs
761+
ON rbs.rid = r.id
762+
AND rbs.build_status != 'in_progress'
763+
JOIN builds AS b
764+
ON b.rid = r.id
765+
AND b.build_finished = rbs.last_build_time
766+
AND b.rustc_nightly_date >= $1
767+
AND b.rustc_nightly_date < $2
768+
765769
766770
"#, start_nightly_date, end_nightly_date
767771
)
@@ -777,16 +781,13 @@ FROM crates AS c
777781
{
778782
results_count += 1;
779783
info!(
780-
"queueing rebuild for {} {} (priority {})...",
781-
&row.name, &row.version, BROKEN_RUSTDOC_REBUILD_PRIORITY
784+
name=%row.name,
785+
version=%row.version,
786+
priority=PRIORITY_BROKEN_RUSTDOC,
787+
"queueing rebuild"
782788
);
783789
build_queue
784-
.add_crate(
785-
&row.name,
786-
&row.version,
787-
BROKEN_RUSTDOC_REBUILD_PRIORITY,
788-
None,
789-
)
790+
.add_crate(&row.name, &row.version, PRIORITY_BROKEN_RUSTDOC, None)
790791
.await?;
791792
}
792793
}
@@ -831,35 +832,41 @@ mod tests {
831832
assert_eq!(queue.len(), 1);
832833
assert_eq!(queue[0].name, "foo");
833834
assert_eq!(queue[0].version, V1);
834-
assert_eq!(queue[0].priority, REBUILD_PRIORITY);
835+
assert_eq!(queue[0].priority, PRIORITY_CONTINUOUS);
835836

836837
Ok(())
837838
}
838839

839-
/// Verifies whether a rebuild is queued for a crate that previously failed with a nightly version of rustdoc.
840+
/// Verifies whether a rebuild is queued for all releases with the latest build performed with a specific nightly version of rustdoc
840841
#[tokio::test(flavor = "multi_thread")]
841842
async fn test_rebuild_broken_rustdoc_specific_date_simple() -> Result<()> {
842-
let env = TestEnvironment::with_config(
843-
TestEnvironment::base_config()
844-
.max_queued_rebuilds(Some(100))
845-
.build()?,
846-
)
847-
.await?;
843+
let env = TestEnvironment::new().await?;
848844

849-
for i in 1..5 {
850-
let nightly_date = NaiveDate::from_ymd_opt(2020, 10, i).unwrap();
845+
// Matrix of test builds (crate name, nightly date, version)
846+
let build_matrix = [
847+
// Should be skipped since this is not the latest build for this release
848+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 1).unwrap(), V1),
849+
// All those should match
850+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(), V1),
851+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(), V2),
852+
("foo2", NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(), V1),
853+
// Should be skipped since the nightly doesn't match
854+
("foo2", NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(), V2),
855+
];
856+
for build in build_matrix.into_iter() {
857+
let (crate_name, nightly, version) = build;
851858
env.fake_release()
852859
.await
853-
.name(&format!("foo{}", i))
854-
.version(V1)
860+
.name(crate_name)
861+
.version(version)
855862
.builds(vec![
856863
FakeBuild::default()
857864
.rustc_version(
858865
format!(
859866
"rustc 1.84.0-nightly (e7c0d2750 {})",
860-
nightly_date.format("%Y-%m-%d")
867+
nightly.format("%Y-%m-%d")
861868
)
862-
.as_str(),
869+
.as_str(),
863870
)
864871
.build_status(BuildStatus::Failure),
865872
])
@@ -874,60 +881,60 @@ mod tests {
874881
queue_rebuilds_faulty_rustdoc(
875882
&mut conn,
876883
build_queue,
877-
&NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(),
884+
&NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(),
878885
&None,
879886
)
880887
.await?;
881888

882889
let queue = build_queue.queued_crates().await?;
883-
assert_eq!(queue.len(), 1);
884-
assert_eq!(queue[0].name, "foo3");
890+
assert_eq!(queue.len(), 3);
891+
assert_eq!(queue[0].name, "foo1");
885892
assert_eq!(queue[0].version, V1);
886-
assert_eq!(queue[0].priority, BROKEN_RUSTDOC_REBUILD_PRIORITY);
893+
assert_eq!(queue[0].priority, PRIORITY_BROKEN_RUSTDOC);
894+
assert_eq!(queue[1].name, "foo1");
895+
assert_eq!(queue[1].version, V2);
896+
assert_eq!(queue[1].priority, PRIORITY_BROKEN_RUSTDOC);
897+
assert_eq!(queue[2].name, "foo2");
898+
assert_eq!(queue[2].version, V1);
899+
assert_eq!(queue[2].priority, PRIORITY_BROKEN_RUSTDOC);
887900

888901
Ok(())
889902
}
890903

891-
/// Verified whether a rebuild is NOT queued since the latest build for the specific crate is marked as successful.
904+
/// Verifies whether a rebuild is NOT queued for any crate if the nightly specified doesn't match any latest build of any release
892905
#[tokio::test(flavor = "multi_thread")]
893906
async fn test_rebuild_broken_rustdoc_specific_date_skipped() -> Result<()> {
894-
let env = TestEnvironment::with_config(
895-
TestEnvironment::base_config()
896-
.max_queued_rebuilds(Some(100))
897-
.build()?,
898-
)
899-
.await?;
907+
let env = TestEnvironment::new().await?;
900908

901-
env.fake_release()
902-
.await
903-
.name("foo")
904-
.version(V1)
905-
.builds(vec![
906-
FakeBuild::default()
907-
.rustc_version(
908-
format!(
909-
"rustc 1.84.0-nightly (e7c0d2750 {})",
910-
NaiveDate::from_ymd_opt(2020, 10, 1)
911-
.unwrap()
912-
.format("%Y-%m-%d")
913-
)
914-
.as_str(),
915-
)
916-
.build_status(BuildStatus::Failure),
917-
FakeBuild::default()
918-
.rustc_version(
919-
format!(
920-
"rustc 1.84.0-nightly (e7c0d2750 {})",
921-
NaiveDate::from_ymd_opt(2020, 10, 1)
922-
.unwrap()
923-
.format("%Y-%m-%d")
909+
// Matrix of test builds (crate name, nightly date, version)
910+
let build_matrix = [
911+
// Should be skipped since this is not the latest build for this release even if the nightly matches
912+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(), V1),
913+
// Should be skipped since the nightly doesn't match
914+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(), V1),
915+
// Should be skipped since the nightly doesn't match
916+
("foo2", NaiveDate::from_ymd_opt(2020, 10, 4).unwrap(), V1),
917+
];
918+
for build in build_matrix.into_iter() {
919+
let (crate_name, nightly, version) = build;
920+
env.fake_release()
921+
.await
922+
.name(crate_name)
923+
.version(version)
924+
.builds(vec![
925+
FakeBuild::default()
926+
.rustc_version(
927+
format!(
928+
"rustc 1.84.0-nightly (e7c0d2750 {})",
929+
nightly.format("%Y-%m-%d")
930+
)
931+
.as_str(),
924932
)
925-
.as_str(),
926-
)
927-
.build_status(BuildStatus::Success),
928-
])
929-
.create()
930-
.await?;
933+
.build_status(BuildStatus::Failure),
934+
])
935+
.create()
936+
.await?;
937+
}
931938

932939
let build_queue = env.async_build_queue();
933940
assert!(build_queue.queued_crates().await?.is_empty());
@@ -936,7 +943,7 @@ mod tests {
936943
queue_rebuilds_faulty_rustdoc(
937944
&mut conn,
938945
build_queue,
939-
&NaiveDate::from_ymd_opt(2020, 10, 1).unwrap(),
946+
&NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(),
940947
&None,
941948
)
942949
.await?;
@@ -947,29 +954,36 @@ mod tests {
947954
Ok(())
948955
}
949956

957+
/// Verifies whether a rebuild is queued for all releases with the latest build performed with a nightly version between two dates
950958
#[tokio::test(flavor = "multi_thread")]
951959
async fn test_rebuild_broken_rustdoc_date_range() -> Result<()> {
952-
let env = TestEnvironment::with_config(
953-
TestEnvironment::base_config()
954-
.max_queued_rebuilds(Some(100))
955-
.build()?,
956-
)
957-
.await?;
960+
let env = TestEnvironment::new().await?;
958961

959-
for i in 1..6 {
960-
let nightly_date = NaiveDate::from_ymd_opt(2020, 10, i).unwrap();
962+
// Matrix of test builds (crate name, nightly date, version)
963+
let build_matrix = [
964+
// Should be skipped since this is not the latest build for this release
965+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 1).unwrap(), V1),
966+
// All those should match
967+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(), V1),
968+
("foo1", NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(), V2),
969+
("foo2", NaiveDate::from_ymd_opt(2020, 10, 4).unwrap(), V1),
970+
// Should be skipped since the nightly doesn't match (end date is exclusive)
971+
("foo2", NaiveDate::from_ymd_opt(2020, 10, 5).unwrap(), V2),
972+
];
973+
for build in build_matrix.into_iter() {
974+
let (crate_name, nightly, version) = build;
961975
env.fake_release()
962976
.await
963-
.name(&format!("foo{}", i))
964-
.version(V1)
977+
.name(crate_name)
978+
.version(version)
965979
.builds(vec![
966980
FakeBuild::default()
967981
.rustc_version(
968982
format!(
969983
"rustc 1.84.0-nightly (e7c0d2750 {})",
970-
nightly_date.format("%Y-%m-%d")
984+
nightly.format("%Y-%m-%d")
971985
)
972-
.as_str(),
986+
.as_str(),
973987
)
974988
.build_status(BuildStatus::Failure),
975989
])
@@ -984,19 +998,22 @@ mod tests {
984998
queue_rebuilds_faulty_rustdoc(
985999
&mut conn,
9861000
build_queue,
987-
&NaiveDate::from_ymd_opt(2020, 10, 3).unwrap(),
1001+
&NaiveDate::from_ymd_opt(2020, 10, 2).unwrap(),
9881002
&NaiveDate::from_ymd_opt(2020, 10, 5),
9891003
)
9901004
.await?;
9911005

9921006
let queue = build_queue.queued_crates().await?;
993-
assert_eq!(queue.len(), 2);
994-
assert_eq!(queue[0].name, "foo3");
1007+
assert_eq!(queue.len(), 3);
1008+
assert_eq!(queue[0].name, "foo1");
9951009
assert_eq!(queue[0].version, V1);
996-
assert_eq!(queue[0].priority, BROKEN_RUSTDOC_REBUILD_PRIORITY);
997-
assert_eq!(queue[1].name, "foo4");
1010+
assert_eq!(queue[0].priority, PRIORITY_BROKEN_RUSTDOC);
1011+
assert_eq!(queue[1].name, "foo1");
1012+
assert_eq!(queue[1].version, V2);
1013+
assert_eq!(queue[1].priority, PRIORITY_BROKEN_RUSTDOC);
1014+
assert_eq!(queue[1].name, "foo2");
9981015
assert_eq!(queue[1].version, V1);
999-
assert_eq!(queue[1].priority, BROKEN_RUSTDOC_REBUILD_PRIORITY);
1016+
assert_eq!(queue[1].priority, PRIORITY_BROKEN_RUSTDOC);
10001017

10011018
Ok(())
10021019
}
@@ -1012,10 +1029,10 @@ mod tests {
10121029

10131030
let build_queue = env.async_build_queue();
10141031
build_queue
1015-
.add_crate("foo1", &V1, REBUILD_PRIORITY, None)
1032+
.add_crate("foo1", &V1, PRIORITY_CONTINUOUS, None)
10161033
.await?;
10171034
build_queue
1018-
.add_crate("foo2", &V1, REBUILD_PRIORITY, None)
1035+
.add_crate("foo2", &V1, PRIORITY_CONTINUOUS, None)
10191036
.await?;
10201037

10211038
let mut conn = env.async_db().async_conn().await;
@@ -1054,10 +1071,10 @@ mod tests {
10541071

10551072
let build_queue = env.async_build_queue();
10561073
build_queue
1057-
.add_crate("foo1", &V1, REBUILD_PRIORITY, None)
1074+
.add_crate("foo1", &V1, PRIORITY_CONTINUOUS, None)
10581075
.await?;
10591076
build_queue
1060-
.add_crate("foo2", &V1, REBUILD_PRIORITY, None)
1077+
.add_crate("foo2", &V1, PRIORITY_CONTINUOUS, None)
10611078
.await?;
10621079

10631080
env.fake_release()

0 commit comments

Comments
 (0)