Skip to content

Commit b8a93e9

Browse files
committed
Feat; job_queue table definition & mark a request as complete if all jobs are finished
1 parent 98ca3ce commit b8a93e9

File tree

6 files changed

+537
-10
lines changed

6 files changed

+537
-10
lines changed

database/schema.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,19 @@ Columns:
313313
execute.
314314
* **is_active** (`boolean NOT NULL`): For controlling whether the collector is
315315
active for use. Useful for adding/removing collectors.
316+
317+
### job_queue
318+
319+
This table stores ephemeral benchmark jobs, which specifically tell the
320+
collector which benchmarks it should execute. The jobs will be kept in the
321+
table for ~30 days after being completed, so that we can quickly figure out
322+
what master parent jobs we need to backfill when handling try builds.
323+
324+
```
325+
psql# SELECT * FROM job_queue limit 1;
326+
327+
id request_id target backend benchmark_set collector_id created_at started_at completed_at status retry error
328+
--- ----------- -------- -------- ------------- -------------- --------------------------- --------------------------- --------------------------- --------- ------ --------
329+
23 7 AArch64 llvm 5 collector-1 2025-07-10 09:00:00.123+00 2025-07-10 09:05:02.456+00 2025-07-10 09:15:17.890+00 complete 0
330+
```
331+
>>>>>>> d0ed82ff (Feat; job_queue table definition & mark a request as complete if all jobs are finished)

database/src/lib.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,10 @@ impl BenchmarkRequest {
10261026
.collect::<Result<Vec<_>, _>>()
10271027
.map_err(|e| anyhow::anyhow!("Invalid backend: {e}"))
10281028
}
1029+
1030+
pub fn is_completed(&self) -> bool {
1031+
matches!(self.status, BenchmarkRequestStatus::Completed { .. })
1032+
}
10291033
}
10301034

10311035
/// Cached information about benchmark requests in the DB
@@ -1047,6 +1051,70 @@ impl BenchmarkRequestIndex {
10471051
pub fn completed_requests(&self) -> &HashSet<String> {
10481052
&self.completed
10491053
}
1054+
1055+
pub fn add_tag(&mut self, tag: &str) {
1056+
self.completed.insert(tag.to_string());
1057+
}
1058+
}
1059+
1060+
#[derive(Debug, Clone, PartialEq)]
1061+
pub enum BenchmarkJobStatus {
1062+
Queued,
1063+
InProgress,
1064+
Success,
1065+
Failure,
1066+
}
1067+
1068+
impl BenchmarkJobStatus {
1069+
pub fn as_str(&self) -> &str {
1070+
match self {
1071+
BenchmarkJobStatus::Queued => "queued",
1072+
BenchmarkJobStatus::InProgress => "in_progress",
1073+
BenchmarkJobStatus::Success => "success",
1074+
BenchmarkJobStatus::Failure => "failure",
1075+
}
1076+
}
1077+
}
1078+
1079+
impl fmt::Display for BenchmarkJobStatus {
1080+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1081+
write!(f, "{}", self.as_str())
1082+
}
1083+
}
1084+
1085+
#[derive(Debug, Clone, PartialEq)]
1086+
pub struct BenchmarkJob {
1087+
pub target: Target,
1088+
pub backend: CodegenBackend,
1089+
pub benchmark_set: u32,
1090+
pub collector_id: String,
1091+
pub created_at: Option<DateTime<Utc>>,
1092+
pub started_at: Option<DateTime<Utc>>,
1093+
pub completed_at: Option<DateTime<Utc>>,
1094+
pub status: BenchmarkJobStatus,
1095+
pub retry: u32,
1096+
}
1097+
1098+
impl BenchmarkJob {
1099+
pub fn new(
1100+
target: Target,
1101+
backend: CodegenBackend,
1102+
benchmark_set: u32,
1103+
collector_id: &str,
1104+
status: BenchmarkJobStatus,
1105+
) -> Self {
1106+
BenchmarkJob {
1107+
target,
1108+
backend,
1109+
benchmark_set,
1110+
collector_id: collector_id.to_string(),
1111+
created_at: None,
1112+
started_at: None,
1113+
completed_at: None,
1114+
status,
1115+
retry: 0,
1116+
}
1117+
}
10501118
}
10511119

10521120
#[derive(Debug, Clone, PartialEq)]

0 commit comments

Comments
 (0)