Skip to content

Commit a6dcd52

Browse files
List all in-progress artifacts
1 parent 145fb1b commit a6dcd52

File tree

6 files changed

+110
-103
lines changed

6 files changed

+110
-103
lines changed

database/src/pool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ pub trait Connection: Send + Sync {
7171
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str) -> bool;
7272
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str);
7373

74-
// Returns an artifact that is in progress.
75-
async fn in_progress_artifact(&self) -> Option<ArtifactId>;
74+
async fn in_progress_artifacts(&self) -> Vec<ArtifactId>;
7675

7776
async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;
7877
}

database/src/pool/postgres.rs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ where
863863
log::error!("did not end {} for {:?}", step, aid);
864864
}
865865
}
866-
async fn in_progress_artifact(&self) -> Option<ArtifactId> {
866+
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
867867
let rows = self
868868
.conn()
869869
.query(
@@ -872,34 +872,46 @@ where
872872
)
873873
.await
874874
.unwrap();
875-
let aid = rows.into_iter().next().map(|row| row.get::<_, i16>(0))?;
875+
let aids = rows
876+
.into_iter()
877+
.map(|row| row.get::<_, i16>(0))
878+
.collect::<Vec<_>>();
876879

877-
let row = self
878-
.conn()
879-
.query_one(
880-
"select name, date, type from artifact where id = $1",
881-
&[&aid],
882-
)
883-
.await
884-
// If we couldn't find the row, early exit with `None`. This is a
885-
// transition state -- wouldn't be needed in the long run.
886-
.ok()?;
887-
888-
let ty = row.get::<_, String>(2);
889-
Some(match ty.as_str() {
890-
"try" | "master" => ArtifactId::Commit(Commit {
891-
sha: row.get(0),
892-
date: row
893-
.get::<_, Option<_>>(1)
894-
.map(Date)
895-
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
896-
}),
897-
"release" => ArtifactId::Artifact(row.get(0)),
898-
_ => {
899-
log::error!("unknown ty {:?}", ty);
900-
return None;
901-
}
902-
})
880+
let mut artifacts = Vec::new();
881+
for aid in aids {
882+
let row = self
883+
.conn()
884+
.query_one(
885+
"select name, date, type from artifact where id = $1",
886+
&[&aid],
887+
)
888+
.await;
889+
890+
let row = match row {
891+
Ok(row) => row,
892+
Err(err) => {
893+
log::error!("skipping aid={} -- no such artifact: {:?}", aid, err);
894+
continue;
895+
}
896+
};
897+
898+
let ty = row.get::<_, String>(2);
899+
artifacts.push(match ty.as_str() {
900+
"try" | "master" => ArtifactId::Commit(Commit {
901+
sha: row.get(0),
902+
date: row
903+
.get::<_, Option<_>>(1)
904+
.map(Date)
905+
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
906+
}),
907+
"release" => ArtifactId::Artifact(row.get(0)),
908+
_ => {
909+
log::error!("unknown ty {:?}", ty);
910+
continue;
911+
}
912+
});
913+
}
914+
artifacts
903915
}
904916
async fn in_progress_steps(&self, artifact: &ArtifactId) -> Vec<crate::Step> {
905917
let aid = self.artifact_id(artifact).await;

database/src/pool/sqlite.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -675,46 +675,50 @@ impl Connection for SqliteConnection {
675675
log::error!("did not end {} for {:?}", step, aid);
676676
}
677677
}
678-
async fn in_progress_artifact(&self) -> Option<ArtifactId> {
679-
let aid = self
680-
.raw_ref()
681-
.query_row(
682-
"select distinct aid from collector_progress where end is null order by aid limit 1",
683-
params![],
684-
|r| r.get::<_, i16>(0),
685-
)
686-
.optional()
687-
.unwrap()?;
688-
689-
let (name, date, ty) = self
690-
.raw_ref()
691-
.query_row(
692-
"select name, date, type from artifact where id = ?",
693-
params![&aid],
694-
|r| {
695-
Ok((
696-
r.get::<_, String>(0)?,
697-
r.get::<_, Option<i64>>(1)?,
698-
r.get::<_, String>(2)?,
699-
))
700-
},
678+
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
679+
let conn = self.raw_ref();
680+
let mut aids = conn
681+
.prepare(
682+
"select distinct aid from collector_progress \
683+
where end is null order by aid limit 1",
701684
)
702685
.unwrap();
703686

704-
Some(match ty.as_str() {
705-
"try" | "master" => ArtifactId::Commit(Commit {
706-
sha: name,
707-
date: date
708-
.map(|d| Utc.timestamp(d, 0))
709-
.map(Date)
710-
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
711-
}),
712-
"release" => ArtifactId::Artifact(name),
713-
_ => {
714-
log::error!("unknown ty {:?}", ty);
715-
return None;
716-
}
717-
})
687+
let aids = aids.query_map(params![], |r| r.get::<_, i16>(0)).unwrap();
688+
689+
let mut artifacts = Vec::new();
690+
for aid in aids {
691+
let aid = aid.unwrap();
692+
let (name, date, ty) = conn
693+
.query_row(
694+
"select name, date, type from artifact where id = ?",
695+
params![&aid],
696+
|r| {
697+
Ok((
698+
r.get::<_, String>(0)?,
699+
r.get::<_, Option<i64>>(1)?,
700+
r.get::<_, String>(2)?,
701+
))
702+
},
703+
)
704+
.unwrap();
705+
706+
artifacts.push(match ty.as_str() {
707+
"try" | "master" => ArtifactId::Commit(Commit {
708+
sha: name,
709+
date: date
710+
.map(|d| Utc.timestamp(d, 0))
711+
.map(Date)
712+
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
713+
}),
714+
"release" => ArtifactId::Artifact(name),
715+
_ => {
716+
log::error!("unknown ty {:?}", ty);
717+
continue;
718+
}
719+
});
720+
}
721+
artifacts
718722
}
719723
async fn in_progress_steps(&self, artifact: &ArtifactId) -> Vec<crate::Step> {
720724
let aid = self.artifact_id(artifact).await;

site/src/github.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -596,26 +596,17 @@ pub async fn post_finished(data: &InputData) {
596596
.collect::<HashSet<_>>();
597597
let queued = conn.queued_commits().await;
598598

599-
// In theory this is insufficient -- there could be multiple commits in
600-
// progress -- but in practice that really shouldn't happen.
601-
//
602-
// The failure case here is also just prematurely posting a single comment,
603-
// which should be fine. mark_complete below will ensure that only happens
604-
// once.
605-
//
606-
// If this becomes more of a problem, it should be fairly easy to instead
607-
// query that there are no in progress benchmarks for commit X.
608-
match conn.in_progress_artifact().await {
609-
None => {}
610-
Some(ArtifactId::Commit(c)) => {
611-
commits.insert(c.sha);
612-
}
613-
Some(ArtifactId::Artifact(_)) => {
614-
// do nothing, for now, though eventually we'll want an artifact
615-
// queue
599+
for aid in conn.in_progress_artifacts().await {
600+
match aid {
601+
ArtifactId::Commit(c) => {
602+
commits.insert(c.sha);
603+
}
604+
ArtifactId::Artifact(_) => {
605+
// do nothing, for now, though eventually we'll want an artifact
606+
// queue
607+
}
616608
}
617609
}
618-
619610
for commit in queued {
620611
if !commits.contains(&commit.sha) {
621612
continue;

site/src/load.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,24 @@ impl InputData {
201201
.chain(missing)
202202
.collect::<Vec<_>>();
203203

204-
match self.conn().await.in_progress_artifact().await {
205-
None => {}
206-
Some(ArtifactId::Commit(c)) => {
207-
commits.insert(
208-
0,
209-
(
210-
rustc_artifacts::Commit {
211-
sha: c.sha,
212-
time: c.date.0,
213-
},
214-
MissingReason::InProgress,
215-
),
216-
);
217-
}
218-
Some(ArtifactId::Artifact(_)) => {
219-
// do nothing, for now, though eventually we'll want an artifact
220-
// queue
204+
for aid in self.conn().await.in_progress_artifacts().await {
205+
match aid {
206+
ArtifactId::Commit(c) => {
207+
commits.insert(
208+
0,
209+
(
210+
rustc_artifacts::Commit {
211+
sha: c.sha,
212+
time: c.date.0,
213+
},
214+
MissingReason::InProgress,
215+
),
216+
);
217+
}
218+
ArtifactId::Artifact(_) => {
219+
// do nothing, for now, though eventually we'll want an artifact
220+
// queue
221+
}
221222
}
222223
}
223224

site/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
277277
let missing = data.missing_commits().await;
278278
// FIXME: no current builds
279279
let conn = data.conn().await;
280-
let current = if let Some(artifact) = conn.in_progress_artifact().await {
280+
let current = if let Some(artifact) = conn.in_progress_artifacts().await.pop() {
281281
let steps = conn
282282
.in_progress_steps(&artifact)
283283
.await

0 commit comments

Comments
 (0)