Skip to content

Commit 3074e36

Browse files
committed
Pr Feedback; expose BenchmarkJob id and create BenchmakrJobConclusion, refactored usages and tests
1 parent 67d30b3 commit 3074e36

File tree

5 files changed

+69
-98
lines changed

5 files changed

+69
-98
lines changed

database/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ pub struct BenchmarkSet(pub u32);
11041104
/// they are responsible for.
11051105
#[derive(Debug, Clone, PartialEq)]
11061106
pub struct BenchmarkJob {
1107+
id: u32,
11071108
target: Target,
11081109
backend: CodegenBackend,
11091110
profile: Profile,
@@ -1115,6 +1116,10 @@ pub struct BenchmarkJob {
11151116
}
11161117

11171118
impl BenchmarkJob {
1119+
pub fn id(&self) -> u32 {
1120+
self.id
1121+
}
1122+
11181123
pub fn target(&self) -> &Target {
11191124
&self.target
11201125
}
@@ -1144,6 +1149,22 @@ impl BenchmarkJob {
11441149
}
11451150
}
11461151

1152+
/// Describes the final state of a job
1153+
#[derive(Debug, Clone, PartialEq)]
1154+
pub enum BenchmarkJobConclusion {
1155+
Failure,
1156+
Success,
1157+
}
1158+
1159+
impl BenchmarkJobConclusion {
1160+
pub fn as_str(&self) -> &str {
1161+
match self {
1162+
BenchmarkJobConclusion::Failure => BENCHMARK_JOB_STATUS_FAILURE_STR,
1163+
BenchmarkJobConclusion::Success => BENCHMARK_JOB_STATUS_SUCCESS_STR,
1164+
}
1165+
}
1166+
}
1167+
11471168
/// The configuration for a collector
11481169
#[derive(Debug, PartialEq)]
11491170
pub struct CollectorConfig {

database/src/pool.rs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::selector::CompileTestCase;
22
use crate::{
3-
ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkJob, BenchmarkJobStatus,
3+
ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkJob, BenchmarkJobConclusion,
44
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend,
55
CollectorConfig, CompileBenchmark, Target,
66
};
@@ -262,10 +262,8 @@ pub trait Connection: Send + Sync {
262262
/// depending on the enum's completed state being a success
263263
async fn mark_benchmark_job_as_completed(
264264
&self,
265-
request_tag: &str,
266-
benchmark_set: u32,
267-
target: &Target,
268-
status: &BenchmarkJobStatus,
265+
id: u32,
266+
benchmark_job_conculsion: &BenchmarkJobConclusion,
269267
) -> anyhow::Result<()>;
270268
}
271269

@@ -409,7 +407,6 @@ mod tests {
409407
benchmark_set: u32,
410408
target: &Target,
411409
) {
412-
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
413410
/* Create job for the request */
414411
db.enqueue_benchmark_job(
415412
request_tag,
@@ -430,19 +427,9 @@ mod tests {
430427
assert_eq!(job.request_tag(), request_tag);
431428

432429
/* Mark the job as complete */
433-
db.mark_benchmark_job_as_completed(
434-
request_tag,
435-
benchmark_set,
436-
&target,
437-
&BenchmarkJobStatus::Completed {
438-
started_at: time,
439-
completed_at: time,
440-
collector_name: collector_name.into(),
441-
success: true,
442-
},
443-
)
444-
.await
445-
.unwrap();
430+
db.mark_benchmark_job_as_completed(job.id(), &BenchmarkJobConclusion::Success)
431+
.await
432+
.unwrap();
446433

447434
db.mark_benchmark_request_as_completed(request_tag)
448435
.await
@@ -968,19 +955,9 @@ mod tests {
968955
assert_eq!(job.request_tag(), benchmark_request.tag().unwrap());
969956

970957
/* Mark the job as complete */
971-
db.mark_benchmark_job_as_completed(
972-
tag,
973-
benchmark_set.0,
974-
&target,
975-
&BenchmarkJobStatus::Completed {
976-
started_at: time,
977-
completed_at: time,
978-
collector_name: collector_name.into(),
979-
success: false,
980-
},
981-
)
982-
.await
983-
.unwrap();
958+
db.mark_benchmark_job_as_completed(job.id(), &BenchmarkJobConclusion::Success)
959+
.await
960+
.unwrap();
984961

985962
db.mark_benchmark_request_as_completed(tag).await.unwrap();
986963

database/src/pool/postgres.rs

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::selector::CompileTestCase;
33
use crate::{
4-
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob, BenchmarkJobStatus,
5-
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestType,
6-
BenchmarkSet, CodegenBackend, CollectionId, CollectorConfig, Commit, CommitType,
7-
CompileBenchmark, Date, Index, Profile, QueuedCommit, Scenario, Target,
8-
BENCHMARK_JOB_STATUS_FAILURE_STR, BENCHMARK_JOB_STATUS_IN_PROGRESS_STR,
4+
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob,
5+
BenchmarkJobConclusion, BenchmarkJobStatus, BenchmarkRequest, BenchmarkRequestIndex,
6+
BenchmarkRequestStatus, BenchmarkRequestType, BenchmarkSet, CodegenBackend, CollectionId,
7+
CollectorConfig, Commit, CommitType, CompileBenchmark, Date, Index, Profile, QueuedCommit,
8+
Scenario, Target, BENCHMARK_JOB_STATUS_FAILURE_STR, BENCHMARK_JOB_STATUS_IN_PROGRESS_STR,
99
BENCHMARK_JOB_STATUS_QUEUED_STR, BENCHMARK_JOB_STATUS_SUCCESS_STR,
1010
BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
1111
BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR, BENCHMARK_REQUEST_STATUS_COMPLETED_STR,
@@ -1849,6 +1849,7 @@ where
18491849
WHERE
18501850
job_queue.id = picked.id
18511851
RETURNING
1852+
job_queue.id,
18521853
job_queue.backend,
18531854
job_queue.profile,
18541855
job_queue.request_tag,
@@ -1874,20 +1875,21 @@ where
18741875
None => Ok(None),
18751876
Some(row) => {
18761877
let job = BenchmarkJob {
1878+
id: row.get::<_, i32>(0) as u32,
18771879
target: *target,
1878-
backend: CodegenBackend::from_str(&row.get::<_, String>(0))
1880+
backend: CodegenBackend::from_str(&row.get::<_, String>(1))
18791881
.map_err(|e| anyhow::anyhow!(e))?,
1880-
profile: Profile::from_str(&row.get::<_, String>(1))
1882+
profile: Profile::from_str(&row.get::<_, String>(2))
18811883
.map_err(|e| anyhow::anyhow!(e))?,
1882-
request_tag: row.get::<_, String>(2),
1884+
request_tag: row.get::<_, String>(3),
18831885
benchmark_set: benchmark_set.clone(),
1884-
created_at: row.get::<_, DateTime<Utc>>(3),
1886+
created_at: row.get::<_, DateTime<Utc>>(4),
18851887
// The job is now in an in_progress state
18861888
status: BenchmarkJobStatus::InProgress {
1887-
started_at: row.get::<_, DateTime<Utc>>(4),
1889+
started_at: row.get::<_, DateTime<Utc>>(5),
18881890
collector_name: collector_name.into(),
18891891
},
1890-
retry: row.get::<_, i32>(5) as u32,
1892+
retry: row.get::<_, i32>(6) as u32,
18911893
};
18921894
Ok(Some(job))
18931895
}
@@ -1949,40 +1951,24 @@ where
19491951

19501952
async fn mark_benchmark_job_as_completed(
19511953
&self,
1952-
request_tag: &str,
1953-
benchmark_set: u32,
1954-
target: &Target,
1955-
status: &BenchmarkJobStatus,
1954+
id: u32,
1955+
benchmark_job_conclusion: &BenchmarkJobConclusion,
19561956
) -> anyhow::Result<()> {
1957-
match status {
1958-
BenchmarkJobStatus::Queued | BenchmarkJobStatus::InProgress { .. } => {
1959-
panic!("Can only mark a job as complete")
1960-
}
1961-
BenchmarkJobStatus::Completed { success, .. } => {
1962-
let status = if *success {
1963-
BENCHMARK_JOB_STATUS_SUCCESS_STR
1964-
} else {
1965-
BENCHMARK_JOB_STATUS_FAILURE_STR
1966-
};
1967-
self.conn()
1968-
.execute(
1969-
"
1970-
UPDATE
1971-
job_queue
1972-
SET
1973-
status = $1,
1974-
completed_at = NOW()
1975-
WHERE
1976-
request_tag = $2
1977-
AND benchmark_set = $3
1978-
AND target = $4",
1979-
&[&status, &request_tag, &(benchmark_set as i32), &target],
1980-
)
1981-
.await
1982-
.context("Failed to mark benchmark job as completed")?;
1983-
Ok(())
1984-
}
1985-
}
1957+
self.conn()
1958+
.execute(
1959+
"
1960+
UPDATE
1961+
job_queue
1962+
SET
1963+
status = $1,
1964+
completed_at = NOW()
1965+
WHERE
1966+
id = $2",
1967+
&[&benchmark_job_conclusion.as_str(), &(id as i32)],
1968+
)
1969+
.await
1970+
.context("Failed to mark benchmark job as completed")?;
1971+
Ok(())
19861972
}
19871973
}
19881974

database/src/pool/sqlite.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::selector::CompileTestCase;
33
use crate::{
4-
ArtifactCollection, ArtifactId, Benchmark, BenchmarkJob, BenchmarkJobStatus, BenchmarkRequest,
5-
BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend, CollectionId,
6-
CollectorConfig, Commit, CommitType, CompileBenchmark, Date, Profile, Target,
4+
ArtifactCollection, ArtifactId, Benchmark, BenchmarkJob, BenchmarkJobConclusion,
5+
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend,
6+
CollectionId, CollectorConfig, Commit, CommitType, CompileBenchmark, Date, Profile, Target,
77
};
88
use crate::{ArtifactIdNumber, Index, QueuedCommit};
99
use chrono::{DateTime, TimeZone, Utc};
@@ -1360,10 +1360,8 @@ impl Connection for SqliteConnection {
13601360

13611361
async fn mark_benchmark_job_as_completed(
13621362
&self,
1363-
_request_tag: &str,
1364-
_benchmark_set: u32,
1365-
_target: &Target,
1366-
_status: &BenchmarkJobStatus,
1363+
_id: u32,
1364+
_benchmark_job_conculsion: &BenchmarkJobConclusion,
13671365
) -> anyhow::Result<()> {
13681366
no_queue_implementation_abort!()
13691367
}

site/src/job_queue/mod.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod tests {
308308
use super::*;
309309
use chrono::{Datelike, Duration, TimeZone, Utc};
310310
use database::{
311-
tests::run_postgres_test, BenchmarkJobStatus, BenchmarkSet, CodegenBackend, Profile,
311+
tests::run_postgres_test, BenchmarkJobConclusion, BenchmarkSet, CodegenBackend, Profile,
312312
};
313313

314314
fn days_ago(day_str: &str) -> chrono::DateTime<Utc> {
@@ -360,7 +360,6 @@ mod tests {
360360
benchmark_set: u32,
361361
target: &Target,
362362
) {
363-
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
364363
/* Create job for the request */
365364
db.enqueue_benchmark_job(
366365
request_tag,
@@ -381,19 +380,9 @@ mod tests {
381380
assert_eq!(job.request_tag(), request_tag);
382381

383382
/* Mark the job as complete */
384-
db.mark_benchmark_job_as_completed(
385-
request_tag,
386-
benchmark_set,
387-
&target,
388-
&BenchmarkJobStatus::Completed {
389-
started_at: time,
390-
completed_at: time,
391-
collector_name: collector_name.into(),
392-
success: true,
393-
},
394-
)
395-
.await
396-
.unwrap();
383+
db.mark_benchmark_job_as_completed(job.id(), &BenchmarkJobConclusion::Success)
384+
.await
385+
.unwrap();
397386

398387
db.mark_benchmark_request_as_completed(request_tag)
399388
.await

0 commit comments

Comments
 (0)