Skip to content

Commit cc65504

Browse files
committed
Insert try without shas and update try with sha's
1 parent 0bb8aee commit cc65504

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

database/src/pool.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ pub trait Connection: Send + Sync {
197197
benchmark_request: &BenchmarkRequest,
198198
benchmark_request_status: BenchmarkRequestStatus,
199199
) -> anyhow::Result<()>;
200+
201+
/// Update a Try commit to have a `sha` and `parent_sha`. Will update the
202+
/// status of the request too a ready state.
203+
async fn attach_shas_to_try_benchmark_request(
204+
&self,
205+
pr: u32,
206+
sha: &str,
207+
parent_sha: &str,
208+
) -> anyhow::Result<()>;
200209
}
201210

202211
#[async_trait::async_trait]
@@ -534,4 +543,40 @@ mod tests {
534543
})
535544
.await;
536545
}
546+
547+
#[tokio::test]
548+
async fn updating_try_commits() {
549+
run_postgres_test(|ctx| async {
550+
let db = ctx.db_client();
551+
let db = db.connection().await;
552+
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
553+
let pr = 42;
554+
555+
let try_benchmark_request = BenchmarkRequest::create_try(
556+
None,
557+
None,
558+
pr,
559+
time,
560+
BenchmarkRequestStatus::WaitingForArtifacts,
561+
"cranelift",
562+
"",
563+
);
564+
db.insert_benchmark_request(&try_benchmark_request).await;
565+
db.attach_shas_to_try_benchmark_request(pr, "foo", "bar")
566+
.await
567+
.unwrap();
568+
let requests = db
569+
.get_benchmark_requests_by_status(&[BenchmarkRequestStatus::ArtifactsReady])
570+
.await
571+
.unwrap();
572+
573+
assert_eq!(requests.len(), 1);
574+
assert_eq!(requests[0].tag(), Some("foo"));
575+
assert_eq!(requests[0].parent_sha(), Some("bar"));
576+
assert_eq!(requests[0].status, BenchmarkRequestStatus::ArtifactsReady);
577+
578+
Ok(ctx)
579+
})
580+
.await;
581+
}
537582
}

database/src/pool/postgres.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,39 @@ where
15251525

15261526
Ok(())
15271527
}
1528+
1529+
async fn attach_shas_to_try_benchmark_request(
1530+
&self,
1531+
pr: u32,
1532+
sha: &str,
1533+
parent_sha: &str,
1534+
) -> anyhow::Result<()> {
1535+
self.conn()
1536+
.execute(
1537+
"UPDATE
1538+
benchmark_request
1539+
SET
1540+
tag = $1,
1541+
parent_sha = $2,
1542+
status = $3
1543+
WHERE
1544+
pr = $4
1545+
AND commit_type = 'try'
1546+
AND tag IS NULL
1547+
AND status = $5;",
1548+
&[
1549+
&sha,
1550+
&parent_sha,
1551+
&BenchmarkRequestStatus::ArtifactsReady,
1552+
&(pr as i32),
1553+
&BenchmarkRequestStatus::WaitingForArtifacts,
1554+
],
1555+
)
1556+
.await
1557+
.context("failed to execute UPDATE benchmark_request")?;
1558+
1559+
Ok(())
1560+
}
15281561
}
15291562

15301563
fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId {

database/src/pool/sqlite.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,15 @@ impl Connection for SqliteConnection {
12821282
) -> anyhow::Result<()> {
12831283
no_queue_implementation_abort!()
12841284
}
1285+
1286+
async fn attach_shas_to_try_benchmark_request(
1287+
&self,
1288+
_pr: u32,
1289+
_sha: &str,
1290+
_parent_sha: &str,
1291+
) -> anyhow::Result<()> {
1292+
no_queue_implementation_abort!()
1293+
}
12851294
}
12861295

12871296
fn parse_artifact_id(ty: &str, sha: &str, date: Option<i64>) -> ArtifactId {

site/src/github.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod client;
22
pub mod comparison_summary;
33

44
use crate::api::github::Commit;
5+
use crate::job_queue::run_new_queue;
56
use crate::load::{MissingReason, SiteCtxt, TryCommit};
67
use std::sync::LazyLock;
78
use std::time::Duration;
@@ -233,6 +234,22 @@ pub async fn rollup_pr_number(
233234
.then_some(issue.number))
234235
}
235236

237+
async fn attach_shas_to_try_benchmark_request(
238+
conn: &dyn database::pool::Connection,
239+
pr: u32,
240+
sha: &str,
241+
parent_sha: &str,
242+
) {
243+
if run_new_queue() {
244+
if let Err(e) = conn
245+
.attach_shas_to_try_benchmark_request(pr, sha, parent_sha)
246+
.await
247+
{
248+
log::error!("Failed to add shas to try commit {}", e);
249+
}
250+
}
251+
}
252+
236253
pub async fn enqueue_shas(
237254
ctxt: &SiteCtxt,
238255
gh_client: &client::Client,
@@ -258,6 +275,15 @@ pub async fn enqueue_shas(
258275
parent_sha: commit_response.parents.remove(0).sha,
259276
};
260277
let conn = ctxt.conn().await;
278+
279+
attach_shas_to_try_benchmark_request(
280+
&*conn,
281+
pr_number,
282+
&try_commit.sha,
283+
&try_commit.parent_sha,
284+
)
285+
.await;
286+
261287
let queued = conn
262288
.pr_attach_commit(
263289
pr_number,

site/src/request_handlers/github.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use crate::github::{
33
client, enqueue_shas, parse_homu_comment, rollup_pr_number, unroll_rollup,
44
COMMENT_MARK_TEMPORARY, RUST_REPO_GITHUB_API_URL,
55
};
6+
use crate::job_queue::run_new_queue;
67
use crate::load::SiteCtxt;
78

9+
use database::{BenchmarkRequest, BenchmarkRequestStatus};
810
use hashbrown::HashMap;
911
use std::sync::Arc;
1012

@@ -72,6 +74,29 @@ async fn handle_issue(
7274
Ok(github::Response)
7375
}
7476

77+
/// The try does not have a `sha` or a `parent_sha` but we need to keep a record
78+
/// of this commit existing. We make sure there can only be one `pr` with a
79+
/// status of `WaitingForArtifacts` to ensure we don't have duplicates.
80+
async fn queue_partial_try_benchmark_request(
81+
conn: &dyn database::pool::Connection,
82+
pr: u32,
83+
backends: &str,
84+
) {
85+
// We only want to run this if the new system is running
86+
if run_new_queue() {
87+
let try_request = BenchmarkRequest::create_try(
88+
None,
89+
None,
90+
pr,
91+
chrono::Utc::now(),
92+
BenchmarkRequestStatus::WaitingForArtifacts,
93+
backends,
94+
"",
95+
);
96+
conn.insert_benchmark_request(&try_request).await;
97+
}
98+
}
99+
75100
async fn handle_rust_timer(
76101
ctxt: Arc<SiteCtxt>,
77102
main_client: &client::Client,
@@ -97,6 +122,13 @@ async fn handle_rust_timer(
97122
let msg = match queue {
98123
Ok(cmd) => {
99124
let conn = ctxt.conn().await;
125+
126+
queue_partial_try_benchmark_request(
127+
&*conn,
128+
issue.number,
129+
cmd.params.backends.unwrap_or(""),
130+
)
131+
.await;
100132
conn.queue_pr(
101133
issue.number,
102134
cmd.params.include,
@@ -137,6 +169,12 @@ async fn handle_rust_timer(
137169
{
138170
let conn = ctxt.conn().await;
139171
for command in &valid_build_cmds {
172+
queue_partial_try_benchmark_request(
173+
&*conn,
174+
issue.number,
175+
command.params.backends.unwrap_or(""),
176+
)
177+
.await;
140178
conn.queue_pr(
141179
issue.number,
142180
command.params.include,

0 commit comments

Comments
 (0)