Skip to content

Commit d45534b

Browse files
committed
Chore; make tag optional for Try benchmark requests
1 parent 62972dc commit d45534b

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

database/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl<'a> tokio_postgres::types::FromSql<'a> for BenchmarkRequestStatus {
842842
pub enum BenchmarkRequestType {
843843
/// A Try commit
844844
Try {
845-
sha: String,
845+
sha: Option<String>,
846846
parent_sha: Option<String>,
847847
pr: u32,
848848
},
@@ -915,7 +915,7 @@ impl BenchmarkRequest {
915915
}
916916

917917
pub fn create_try(
918-
sha: &str,
918+
sha: Option<&str>,
919919
parent_sha: Option<&str>,
920920
pr: u32,
921921
created_at: DateTime<Utc>,
@@ -926,7 +926,7 @@ impl BenchmarkRequest {
926926
Self {
927927
commit_type: BenchmarkRequestType::Try {
928928
pr,
929-
sha: sha.to_string(),
929+
sha: sha.map(|it| it.to_string()),
930930
parent_sha: parent_sha.map(|it| it.to_string()),
931931
},
932932
created_at,
@@ -962,10 +962,11 @@ impl BenchmarkRequest {
962962

963963
/// Get either the `sha` for a `try` or `master` commit or a `tag` for a
964964
/// `release`
965-
pub fn tag(&self) -> &str {
965+
pub fn tag(&self) -> Option<&str> {
966966
match &self.commit_type {
967-
BenchmarkRequestType::Try { sha, .. } | BenchmarkRequestType::Master { sha, .. } => sha,
968-
BenchmarkRequestType::Release { tag } => tag,
967+
BenchmarkRequestType::Try { sha, .. } => sha.as_deref(),
968+
BenchmarkRequestType::Master { sha, .. } => Some(sha),
969+
BenchmarkRequestType::Release { tag } => Some(tag),
969970
}
970971
}
971972

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ mod tests {
409409
);
410410

411411
let try_benchmark_request = BenchmarkRequest::create_try(
412-
"b-sha-2",
412+
Some("b-sha-2"),
413413
Some("parent-sha-2"),
414414
32,
415415
time,
@@ -457,7 +457,7 @@ mod tests {
457457
);
458458

459459
let try_benchmark_request = BenchmarkRequest::create_try(
460-
"b-sha-2",
460+
Some("b-sha-2"),
461461
Some("parent-sha-2"),
462462
32,
463463
time,

database/src/pool/postgres.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ static MIGRATIONS: &[&str] = &[
301301
);
302302
CREATE INDEX IF NOT EXISTS benchmark_request_status_idx on benchmark_request (status) WHERE status != 'completed';
303303
"#,
304+
// Remove that tag cannot be NULL
305+
r#"ALTER TABLE benchmark_request ALTER COLUMN tag DROP NOT NULL;"#,
306+
// Prevent multiple try commits without a `sha` being added to the table
307+
r#"CREATE UNIQUE INDEX benchmark_request_pr_status_idx ON benchmark_request (pr, commit_type) WHERE tag IS NULL;"#,
304308
];
305309

306310
#[async_trait::async_trait]
@@ -1457,7 +1461,7 @@ where
14571461
match commit_type {
14581462
"try" => {
14591463
let mut try_benchmark = BenchmarkRequest::create_try(
1460-
tag,
1464+
Some(tag),
14611465
parent_sha,
14621466
pr.unwrap() as u32,
14631467
created_at,

site/src/job_queue.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ fn sort_benchmark_requests(done: &HashSet<String>, request_queue: &mut [Benchmar
182182
)
183183
});
184184
for c in level {
185-
done.insert(c.tag().to_string());
185+
if let Some(tag) = c.tag() {
186+
done.insert(tag.to_string());
187+
}
186188
}
187189
finished += level_len;
188190
}
@@ -241,7 +243,7 @@ pub async fn build_queue(
241243

242244
release_artifacts.sort_unstable_by(|a, b| {
243245
a.tag()
244-
.cmp(b.tag())
246+
.cmp(&b.tag())
245247
.then_with(|| a.created_at.cmp(&b.created_at))
246248
});
247249

@@ -258,7 +260,7 @@ async fn enqueue_next_job(conn: &mut dyn database::pool::Connection) -> anyhow::
258260
.get_benchmark_requests_by_status(&[BenchmarkRequestStatus::Completed])
259261
.await?
260262
.into_iter()
261-
.map(|request| request.tag().to_string())
263+
.filter_map(|request| request.tag().map(|tag| tag.to_string()))
262264
.collect();
263265

264266
let queue = build_queue(conn, &completed).await?;
@@ -360,7 +362,7 @@ mod tests {
360362

361363
fn create_try(sha: &str, parent: &str, pr: u32, age_days: &str) -> BenchmarkRequest {
362364
BenchmarkRequest::create_try(
363-
sha,
365+
Some(sha),
364366
Some(parent),
365367
pr,
366368
days_ago(age_days),
@@ -390,7 +392,10 @@ mod tests {
390392
}
391393

392394
fn queue_order_matches(queue: &[BenchmarkRequest], expected: &[&str]) {
393-
let queue_shas: Vec<&str> = queue.iter().map(|req| req.tag()).collect();
395+
let queue_shas: Vec<&str> = queue
396+
.iter()
397+
.filter_map(|request| request.tag().map(|tag| tag))
398+
.collect();
394399
assert_eq!(queue_shas, expected)
395400
}
396401

0 commit comments

Comments
 (0)