Skip to content

Commit 96b2846

Browse files
authored
Merge pull request #2257 from Jamesbarford/fix/enqueue-job
Fix; enqueuing a job that has already been enqueued
2 parents 85d4fe5 + 8a547ff commit 96b2846

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

database/src/pool.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,16 @@ pub trait Connection: Send + Sync {
224224
commit_date: DateTime<Utc>,
225225
) -> anyhow::Result<()>;
226226

227-
/// Add a benchmark job to the job queue and return its ID.
227+
/// Add a benchmark job to the job queue and returns its ID, if it was not
228+
/// already in the DB previously.
228229
async fn enqueue_benchmark_job(
229230
&self,
230231
request_tag: &str,
231232
target: Target,
232233
backend: CodegenBackend,
233234
profile: Profile,
234235
benchmark_set: u32,
235-
) -> anyhow::Result<u32>;
236+
) -> anyhow::Result<Option<u32>>;
236237

237238
/// Add a benchmark job which is explicitly using a `parent_sha` we split
238239
/// this out to improve our error handling. A `parent_sha` may not have

database/src/pool/postgres.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,10 +1804,11 @@ where
18041804
backend: CodegenBackend,
18051805
profile: Profile,
18061806
benchmark_set: u32,
1807-
) -> anyhow::Result<u32> {
1808-
let row = self
1807+
) -> anyhow::Result<Option<u32>> {
1808+
// This will return zero rows if the job already exists
1809+
let rows = self
18091810
.conn()
1810-
.query_one(
1811+
.query(
18111812
r#"
18121813
INSERT INTO job_queue(
18131814
request_tag,
@@ -1832,7 +1833,11 @@ where
18321833
)
18331834
.await
18341835
.context("failed to insert benchmark_job")?;
1835-
Ok(row.get::<_, i32>(0) as u32)
1836+
if let Some(row) = rows.first() {
1837+
return Ok(Some(row.get::<_, i32>(0) as u32));
1838+
} else {
1839+
return Ok(None);
1840+
}
18361841
}
18371842

18381843
async fn get_compile_test_cases_with_measurements(

database/src/pool/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ impl Connection for SqliteConnection {
13351335
_backend: CodegenBackend,
13361336
_profile: Profile,
13371337
_benchmark_set: u32,
1338-
) -> anyhow::Result<u32> {
1338+
) -> anyhow::Result<Option<u32>> {
13391339
no_queue_implementation_abort!()
13401340
}
13411341

database/src/tests/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl RequestBuilder {
4949
)
5050
.await
5151
.unwrap();
52-
self.jobs.push((job.clone(), id));
52+
self.jobs.push((job.clone(), id.unwrap()));
5353
}
5454
self
5555
}

0 commit comments

Comments
 (0)