|
1 | 1 | use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction}; |
2 | 2 | use crate::{ |
3 | | - ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, CodegenBackend, CollectionId, |
4 | | - Commit, CommitType, CompileBenchmark, Date, Index, Profile, QueuedCommit, Scenario, Target, |
| 3 | + ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkRequest, |
| 4 | + BenchmarkRequestType, CodegenBackend, CollectionId, Commit, CommitType, CompileBenchmark, Date, |
| 5 | + Index, Profile, QueuedCommit, Scenario, Target, |
5 | 6 | }; |
6 | 7 | use anyhow::Context as _; |
7 | 8 | use chrono::{DateTime, TimeZone, Utc}; |
@@ -285,6 +286,22 @@ static MIGRATIONS: &[&str] = &[ |
285 | 286 | alter table pstat_series drop constraint test_case; |
286 | 287 | alter table pstat_series add constraint test_case UNIQUE(crate, profile, scenario, backend, target, metric); |
287 | 288 | "#, |
| 289 | + r#" |
| 290 | + CREATE TABLE IF NOT EXISTS benchmark_requests ( |
| 291 | + id SERIAL PRIMARY KEY, |
| 292 | + tag TEXT NOT NULL UNIQUE, |
| 293 | + parent_sha TEXT, |
| 294 | + commit_type TEXT, |
| 295 | + pr INTEGER, |
| 296 | + created_at TIMESTAMPTZ NOT NULL, |
| 297 | + completed_at TIMESTAMPTZ, |
| 298 | + status TEXT NOT NULL, |
| 299 | + backends TEXT, |
| 300 | + profiles TEXT |
| 301 | + ); |
| 302 | + CREATE INDEX IF NOT EXISTS benchmark_requests_status_idx on benchmark_requests (status); |
| 303 | + CREATE INDEX IF NOT EXISTS benchmark_requests_commit_type on benchmark_requests (commit_type); |
| 304 | + "#, |
288 | 305 | ]; |
289 | 306 |
|
290 | 307 | #[async_trait::async_trait] |
@@ -1365,6 +1382,66 @@ where |
1365 | 1382 | .await |
1366 | 1383 | .unwrap(); |
1367 | 1384 | } |
| 1385 | + |
| 1386 | + async fn insert_benchmark_request(&self, benchmark_request: &BenchmarkRequest) { |
| 1387 | + match &benchmark_request.commit_type { |
| 1388 | + BenchmarkRequestType::Try { |
| 1389 | + sha, |
| 1390 | + parent_sha, |
| 1391 | + pr, |
| 1392 | + } |
| 1393 | + | BenchmarkRequestType::Master { |
| 1394 | + sha, |
| 1395 | + parent_sha, |
| 1396 | + pr, |
| 1397 | + } => { |
| 1398 | + self.conn() |
| 1399 | + .execute( |
| 1400 | + r#" |
| 1401 | + INSERT INTO |
| 1402 | + benchmark_requests(parent_sha, pr, tag, created_at, |
| 1403 | + commit_type, status, backends, profiles) |
| 1404 | + VALUES ($1, $2, $3, $4, $5, $6, $7, $8) |
| 1405 | + ON CONFLICT DO NOTHING; |
| 1406 | + "#, |
| 1407 | + &[ |
| 1408 | + &parent_sha, |
| 1409 | + pr, |
| 1410 | + sha, |
| 1411 | + &benchmark_request.created_at, |
| 1412 | + &benchmark_request.commit_type.to_string(), |
| 1413 | + &benchmark_request.status.to_string(), |
| 1414 | + &benchmark_request.backends, |
| 1415 | + &benchmark_request.profiles, |
| 1416 | + ], |
| 1417 | + ) |
| 1418 | + .await |
| 1419 | + .unwrap(); |
| 1420 | + } |
| 1421 | + BenchmarkRequestType::Release { tag } => { |
| 1422 | + self.conn() |
| 1423 | + .execute( |
| 1424 | + r#" |
| 1425 | + INSERT INTO |
| 1426 | + benchmark_requests(tag, created_at, commit_type, |
| 1427 | + status, backends, profiles) |
| 1428 | + VALUES ($1, $2, $3, $4, $5, $6); |
| 1429 | + ON CONFLICT DO NOTHING; |
| 1430 | + "#, |
| 1431 | + &[ |
| 1432 | + tag, |
| 1433 | + &benchmark_request.created_at, |
| 1434 | + &benchmark_request.commit_type.to_string(), |
| 1435 | + &benchmark_request.status.to_string(), |
| 1436 | + &benchmark_request.backends, |
| 1437 | + &benchmark_request.profiles, |
| 1438 | + ], |
| 1439 | + ) |
| 1440 | + .await |
| 1441 | + .unwrap(); |
| 1442 | + } |
| 1443 | + } |
| 1444 | + } |
1368 | 1445 | } |
1369 | 1446 |
|
1370 | 1447 | fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId { |
|
0 commit comments