|
1 | 1 | use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction}; |
2 | 2 | use crate::{ |
3 | | - ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkRequest, |
4 | | - BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestType, CodegenBackend, |
5 | | - CollectionId, Commit, CommitType, CompileBenchmark, Date, Index, Profile, QueuedCommit, |
6 | | - Scenario, Target, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR, |
| 3 | + ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJobStatus, |
| 4 | + BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestType, |
| 5 | + CodegenBackend, CollectionId, Commit, CommitType, CompileBenchmark, Date, Index, Profile, |
| 6 | + QueuedCommit, Scenario, Target, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR, |
7 | 7 | BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR, BENCHMARK_REQUEST_STATUS_COMPLETED_STR, |
8 | 8 | BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR, BENCHMARK_REQUEST_TRY_STR, |
9 | 9 | }; |
@@ -324,6 +324,42 @@ static MIGRATIONS: &[&str] = &[ |
324 | 324 | CREATE UNIQUE INDEX collector_config_target_bench_active_uniq ON collector_config |
325 | 325 | (target, benchmark_set, is_active) WHERE is_active = TRUE; |
326 | 326 | "#, |
| 327 | + r#" |
| 328 | + CREATE TABLE IF NOT EXISTS job_queue ( |
| 329 | + id SERIAL PRIMARY KEY, |
| 330 | + request_tag TEXT NOT NULL, |
| 331 | + target TEXT NOT NULL, |
| 332 | + backend TEXT NOT NULL, |
| 333 | + profile TEXT NOT NULL, |
| 334 | + benchmark_set INTEGER NOT NULL, |
| 335 | + collector_id INTEGER, |
| 336 | + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), |
| 337 | + started_at TIMESTAMPTZ, |
| 338 | + completed_at TIMESTAMPTZ, |
| 339 | + status TEXT NOT NULL, |
| 340 | + retry INTEGER DEFAULT 0, |
| 341 | +
|
| 342 | + CONSTRAINT job_queue_request_fk |
| 343 | + FOREIGN KEY (request_tag) |
| 344 | + REFERENCES benchmark_request(tag) |
| 345 | + ON DELETE CASCADE, |
| 346 | +
|
| 347 | + CONSTRAINT job_queue_collector |
| 348 | + FOREIGN KEY (collector_id) |
| 349 | + REFERENCES collector_config(id) |
| 350 | + ON DELETE CASCADE, |
| 351 | +
|
| 352 | + CONSTRAINT job_queue_unique |
| 353 | + UNIQUE ( |
| 354 | + request_tag, |
| 355 | + target, |
| 356 | + backend, |
| 357 | + profile, |
| 358 | + benchmark_set |
| 359 | + ) |
| 360 | + ); |
| 361 | + CREATE INDEX IF NOT EXISTS job_queue_request_tag_idx ON job_queue (request_tag); |
| 362 | + "#, |
327 | 363 | ]; |
328 | 364 |
|
329 | 365 | #[async_trait::async_trait] |
@@ -1608,6 +1644,42 @@ where |
1608 | 1644 | .collect(); |
1609 | 1645 | Ok(requests) |
1610 | 1646 | } |
| 1647 | + |
| 1648 | + async fn enqueue_benchmark_job( |
| 1649 | + &self, |
| 1650 | + request_tag: &str, |
| 1651 | + target: &Target, |
| 1652 | + backend: &CodegenBackend, |
| 1653 | + profile: &Profile, |
| 1654 | + benchmark_set: u32, |
| 1655 | + ) -> anyhow::Result<()> { |
| 1656 | + self.conn() |
| 1657 | + .execute( |
| 1658 | + r#" |
| 1659 | + INSERT INTO job_queue( |
| 1660 | + request_tag, |
| 1661 | + target, |
| 1662 | + backend, |
| 1663 | + profile, |
| 1664 | + benchmark_set, |
| 1665 | + status |
| 1666 | + ) |
| 1667 | + VALUES ($1, $2, $3, $4, $5, $6) |
| 1668 | + ON CONFLICT DO NOTHING |
| 1669 | + "#, |
| 1670 | + &[ |
| 1671 | + &request_tag, |
| 1672 | + &target, |
| 1673 | + &backend, |
| 1674 | + &profile, |
| 1675 | + &(benchmark_set as i32), |
| 1676 | + &BenchmarkJobStatus::Queued, |
| 1677 | + ], |
| 1678 | + ) |
| 1679 | + .await |
| 1680 | + .context("failed to insert benchmark_job")?; |
| 1681 | + Ok(()) |
| 1682 | + } |
1611 | 1683 | } |
1612 | 1684 |
|
1613 | 1685 | fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId { |
@@ -1653,6 +1725,10 @@ macro_rules! impl_to_postgresql_via_to_string { |
1653 | 1725 |
|
1654 | 1726 | impl_to_postgresql_via_to_string!(BenchmarkRequestType); |
1655 | 1727 | impl_to_postgresql_via_to_string!(BenchmarkRequestStatus); |
| 1728 | +impl_to_postgresql_via_to_string!(Target); |
| 1729 | +impl_to_postgresql_via_to_string!(CodegenBackend); |
| 1730 | +impl_to_postgresql_via_to_string!(Profile); |
| 1731 | +impl_to_postgresql_via_to_string!(BenchmarkJobStatus); |
1656 | 1732 |
|
1657 | 1733 | #[cfg(test)] |
1658 | 1734 | mod tests { |
|
0 commit comments