Skip to content

Commit be31ac4

Browse files
Merge pull request #721 from Mark-Simulacrum/fix-finishers
Fix finishing comments being posted early
2 parents d2c387b + b890973 commit be31ac4

File tree

8 files changed

+157
-132
lines changed

8 files changed

+157
-132
lines changed

collector/src/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,23 @@ fn bench(
207207
);
208208
}
209209

210-
let interned_cid = rt.block_on(conn.artifact_id(&cid));
211-
212-
let start = Instant::now();
213210
let steps = benchmarks
214211
.iter()
215212
.map(|b| b.name.to_string())
216213
.collect::<Vec<_>>();
217-
rt.block_on(conn.collector_start(interned_cid, &steps));
214+
215+
// Make sure there is no observable time when the artifact ID is available
216+
// but the in-progress steps are not.
217+
let interned_cid = {
218+
let mut tx = rt.block_on(conn.transaction());
219+
let interned_cid = rt.block_on(tx.conn().artifact_id(&cid));
220+
rt.block_on(tx.conn().collector_start(interned_cid, &steps));
221+
222+
rt.block_on(tx.commit()).unwrap();
223+
interned_cid
224+
};
225+
226+
let start = Instant::now();
218227
let mut skipped = false;
219228
for (nth_benchmark, benchmark) in benchmarks.iter().enumerate() {
220229
let is_fresh =

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/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub mod status {
190190

191191
#[derive(Serialize, Debug)]
192192
pub struct Response {
193-
pub last_commit: Commit,
193+
pub last_commit: Option<Commit>,
194194
pub benchmarks: Vec<BenchmarkStatus>,
195195
pub missing: Vec<(Commit, MissingReason)>,
196196
pub current: Option<CurrentState>,

site/src/github.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ where
582582
}
583583

584584
pub async fn post_finished(data: &InputData) {
585+
// If the github token is not configured, do not run this -- we don't want
586+
// to mark things as complete without posting the comment.
587+
if data.config.keys.github.is_none() {
588+
return;
589+
}
585590
let conn = data.conn().await;
586591
let index = data.index.load();
587592
let mut commits = index
@@ -591,26 +596,17 @@ pub async fn post_finished(data: &InputData) {
591596
.collect::<HashSet<_>>();
592597
let queued = conn.queued_commits().await;
593598

594-
// In theory this is insufficient -- there could be multiple commits in
595-
// progress -- but in practice that really shouldn't happen.
596-
//
597-
// The failure case here is also just prematurely posting a single comment,
598-
// which should be fine. mark_complete below will ensure that only happens
599-
// once.
600-
//
601-
// If this becomes more of a problem, it should be fairly easy to instead
602-
// query that there are no in progress benchmarks for commit X.
603-
match conn.in_progress_artifact().await {
604-
None => {}
605-
Some(ArtifactId::Commit(c)) => {
606-
commits.insert(c.sha);
607-
}
608-
Some(ArtifactId::Artifact(_)) => {
609-
// do nothing, for now, though eventually we'll want an artifact
610-
// queue
599+
for aid in conn.in_progress_artifacts().await {
600+
match aid {
601+
ArtifactId::Commit(c) => {
602+
commits.remove(&c.sha);
603+
}
604+
ArtifactId::Artifact(_) => {
605+
// do nothing, for now, though eventually we'll want an artifact
606+
// queue
607+
}
611608
}
612609
}
613-
614610
for commit in queued {
615611
if !commits.contains(&commit.sha) {
616612
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: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,35 +249,12 @@ fn prettify_log(log: &str) -> Option<String> {
249249

250250
pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
251251
let idx = data.index.load();
252-
let last_commit = idx.commits().last().unwrap().clone();
253-
254-
let mut benchmark_state = data
255-
.conn()
256-
.await
257-
.get_error(ArtifactId::from(last_commit.clone()).lookup(&idx).unwrap())
258-
.await
259-
.into_iter()
260-
.map(|(name, error)| {
261-
let msg = if let Some(error) = error {
262-
Some(prettify_log(&error).unwrap_or(error))
263-
} else {
264-
None
265-
};
266-
status::BenchmarkStatus {
267-
name,
268-
success: msg.is_none(),
269-
error: msg,
270-
}
271-
})
272-
.collect::<Vec<_>>();
273-
274-
benchmark_state.sort_by_key(|s| s.error.is_some());
275-
benchmark_state.reverse();
252+
let last_commit = idx.commits().last().cloned();
276253

277254
let missing = data.missing_commits().await;
278255
// FIXME: no current builds
279256
let conn = data.conn().await;
280-
let current = if let Some(artifact) = conn.in_progress_artifact().await {
257+
let current = if let Some(artifact) = conn.in_progress_artifacts().await.pop() {
281258
let steps = conn
282259
.in_progress_steps(&artifact)
283260
.await
@@ -298,6 +275,33 @@ pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
298275
None
299276
};
300277

278+
let errors = if let Some(last) = &last_commit {
279+
data.conn()
280+
.await
281+
.get_error(ArtifactId::from(last.clone()).lookup(&idx).unwrap())
282+
.await
283+
} else {
284+
Default::default()
285+
};
286+
let mut benchmark_state = errors
287+
.into_iter()
288+
.map(|(name, error)| {
289+
let msg = if let Some(error) = error {
290+
Some(prettify_log(&error).unwrap_or(error))
291+
} else {
292+
None
293+
};
294+
status::BenchmarkStatus {
295+
name,
296+
success: msg.is_none(),
297+
error: msg,
298+
}
299+
})
300+
.collect::<Vec<_>>();
301+
302+
benchmark_state.sort_by_key(|s| s.error.is_some());
303+
benchmark_state.reverse();
304+
301305
status::Response {
302306
last_commit,
303307
benchmarks: benchmark_state,

0 commit comments

Comments
 (0)