Skip to content

Commit 446ad17

Browse files
Currently benchmarked commit is at front of queue
1 parent 5d7ffee commit 446ad17

File tree

4 files changed

+106
-8
lines changed

4 files changed

+106
-8
lines changed

database/src/pool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ pub trait Connection: Send + Sync {
7070
// an end. Otherwise returns false, indicating that we can skip it.
7171
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str) -> bool;
7272
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str);
73+
74+
// Returns an artifact that is in progress.
75+
async fn in_progress_artifact(&self) -> Option<ArtifactId>;
7376
}
7477

7578
#[async_trait::async_trait]

database/src/pool/postgres.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactIdNumber, Cache, CollectionId, Commit, Crate, Date, Index, Profile, QueuedCommit,
3+
ArtifactId, ArtifactIdNumber, Cache, CollectionId, Commit, Crate, Date, Index, Profile,
4+
QueuedCommit,
45
};
56
use anyhow::Context as _;
67
use chrono::{DateTime, TimeZone, Utc};
@@ -660,9 +661,9 @@ where
660661
.unwrap();
661662
}
662663

663-
async fn artifact_id(&self, artifact: &crate::ArtifactId) -> ArtifactIdNumber {
664+
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber {
664665
let (name, date, ty) = match artifact {
665-
crate::ArtifactId::Commit(commit) => (
666+
ArtifactId::Commit(commit) => (
666667
commit.sha.to_string(),
667668
if commit.is_try() {
668669
None
@@ -671,7 +672,7 @@ where
671672
},
672673
if commit.is_try() { "try" } else { "master" },
673674
),
674-
crate::ArtifactId::Artifact(a) => (a.clone(), None, "release"),
675+
ArtifactId::Artifact(a) => (a.clone(), None, "release"),
675676
};
676677

677678
let aid = self.conn()
@@ -830,4 +831,37 @@ where
830831
log::error!("did not end {} for {:?}", step, aid);
831832
}
832833
}
834+
async fn in_progress_artifact(&self) -> Option<ArtifactId> {
835+
let rows = self
836+
.conn()
837+
.query(
838+
"select distinct aid from collector_progress where end_time is null order by aid limit 1",
839+
&[],
840+
)
841+
.await
842+
.unwrap();
843+
let aid = rows.into_iter().next().map(|row| row.get::<_, i16>(0))?;
844+
845+
let row = self
846+
.conn()
847+
.query_one(
848+
"select name, date, type from artifact where id = $1",
849+
&[&aid],
850+
)
851+
.await
852+
.unwrap();
853+
854+
let ty = row.get::<_, String>(2);
855+
Some(match ty.as_str() {
856+
"try" | "master" => ArtifactId::Commit(Commit {
857+
sha: row.get(0),
858+
date: Date(row.get(1)),
859+
}),
860+
"release" => ArtifactId::Artifact(row.get(0)),
861+
_ => {
862+
log::error!("unknown ty {:?}", ty);
863+
return None;
864+
}
865+
})
866+
}
833867
}

database/src/pool/sqlite.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2+
use crate::{ArtifactId, CollectionId, Commit, Crate, Date, Profile};
23
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
3-
use crate::{CollectionId, Commit, Crate, Date, Profile};
44
use chrono::{TimeZone, Utc};
55
use hashbrown::HashMap;
66
use rusqlite::params;
@@ -675,4 +675,45 @@ 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+
},
701+
)
702+
.unwrap();
703+
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+
})
718+
}
678719
}

site/src/load.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum MissingReason {
3434
Sha,
3535
TryParent,
3636
TryCommit,
37+
InProgress,
3738
}
3839

3940
#[derive(Clone, Deserialize, Serialize, Debug)]
@@ -151,9 +152,8 @@ impl InputData {
151152
.context("getting master commit list")
152153
.unwrap();
153154

154-
let have = self
155-
.index
156-
.load()
155+
let index = self.index.load();
156+
let have = index
157157
.commits()
158158
.iter()
159159
.map(|commit| commit.sha.clone())
@@ -208,6 +208,26 @@ impl InputData {
208208
.chain(missing)
209209
.collect::<Vec<_>>();
210210

211+
match self.conn().await.in_progress_artifact().await {
212+
None => {}
213+
Some(ArtifactId::Commit(c)) => {
214+
commits.insert(
215+
0,
216+
(
217+
rustc_artifacts::Commit {
218+
sha: c.sha,
219+
time: c.date.0,
220+
},
221+
MissingReason::InProgress,
222+
),
223+
);
224+
}
225+
Some(ArtifactId::Artifact(_)) => {
226+
// do nothing, for now, though eventually we'll want an artifact
227+
// queue
228+
}
229+
}
230+
211231
let mut seen = HashSet::with_capacity(commits.len());
212232

213233
// FIXME: replace with Vec::drain_filter when it stabilizes

0 commit comments

Comments
 (0)