@@ -526,6 +526,7 @@ pub struct CachedStatements {
526526 get_last_n_completed_requests_with_errors : Statement ,
527527 get_jobs_of_in_progress_benchmark_requests : Statement ,
528528 load_pending_benchmark_requests : Statement ,
529+ get_jobs_of_benchmark_requests : Statement ,
529530}
530531
531532pub struct PostgresTransaction < ' a > {
@@ -763,6 +764,11 @@ impl PostgresConnection {
763764 FROM pending
764765 LEFT JOIN benchmark_request as parent ON parent.tag = pending.parent_sha
765766 " ) ) . await . unwrap ( ) ,
767+ get_jobs_of_benchmark_requests : conn. prepare ( "
768+ SELECT *
769+ FROM job_queue
770+ WHERE request_tag = ANY($1)
771+ " ) . await . unwrap ( ) ,
766772 } ) ,
767773 conn,
768774 }
@@ -773,6 +779,44 @@ impl PostgresConnection {
773779const BENCHMARK_REQUEST_COLUMNS : & str =
774780 "tag, parent_sha, pr, commit_type, status, created_at, completed_at, backends, profiles, commit_date, duration_ms, targets" ;
775781
782+ /// Parse a benchmark job out of a row.
783+ /// Expects to be used with `SELECT * FROM job_queue`.
784+ fn parse_benchmark_job_from_row ( row : & Row ) -> anyhow:: Result < BenchmarkJob > {
785+ let started_at = row. get :: < _ , Option < DateTime < Utc > > > ( 7 ) ;
786+ let status = row. get :: < _ , & str > ( 9 ) ;
787+ let collector_name = row. get :: < _ , Option < String > > ( 11 ) ;
788+ let status = match status {
789+ BENCHMARK_JOB_STATUS_QUEUED_STR => BenchmarkJobStatus :: Queued ,
790+ BENCHMARK_JOB_STATUS_IN_PROGRESS_STR => BenchmarkJobStatus :: InProgress {
791+ started_at : started_at. expect ( "started_at was null for an in progress job" ) ,
792+ collector_name : collector_name. expect ( "Collector is missing for an in progress job" ) ,
793+ } ,
794+ BENCHMARK_JOB_STATUS_FAILURE_STR | BENCHMARK_JOB_STATUS_SUCCESS_STR => {
795+ BenchmarkJobStatus :: Completed {
796+ started_at : started_at. expect ( "started_at was null for a finished job" ) ,
797+ completed_at : row. get :: < _ , DateTime < Utc > > ( 8 ) ,
798+ collector_name : collector_name
799+ . expect ( "Collector is missing for an in progress job" ) ,
800+ success : status == BENCHMARK_JOB_STATUS_SUCCESS_STR ,
801+ }
802+ }
803+ _ => panic ! ( "Invalid job status {status}" ) ,
804+ } ;
805+ Ok ( BenchmarkJob {
806+ id : row. get :: < _ , i32 > ( 0 ) as u32 ,
807+ request_tag : row. get :: < _ , String > ( 1 ) ,
808+ target : Target :: from_str ( row. get :: < _ , & str > ( 2 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
809+ backend : CodegenBackend :: from_str ( row. get :: < _ , & str > ( 3 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
810+ profile : Profile :: from_str ( row. get :: < _ , & str > ( 4 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
811+ benchmark_set : BenchmarkSet ( row. get :: < _ , i32 > ( 5 ) as u32 ) ,
812+ created_at : row. get :: < _ , DateTime < Utc > > ( 6 ) ,
813+ status,
814+ deque_counter : row. get :: < _ , i32 > ( 10 ) as u32 ,
815+ kind : BenchmarkJobKind :: from_str ( row. get :: < _ , & str > ( 12 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
816+ is_optional : row. get :: < _ , bool > ( 13 ) ,
817+ } )
818+ }
819+
776820#[ async_trait:: async_trait]
777821impl < P > Connection for P
778822where
@@ -2000,43 +2044,7 @@ where
20002044
20012045 let mut request_to_jobs: HashMap < String , Vec < BenchmarkJob > > = HashMap :: new ( ) ;
20022046 for row in rows {
2003- let started_at = row. get :: < _ , Option < DateTime < Utc > > > ( 7 ) ;
2004- let status = row. get :: < _ , & str > ( 9 ) ;
2005- let collector_name = row. get :: < _ , Option < String > > ( 11 ) ;
2006- let status = match status {
2007- BENCHMARK_JOB_STATUS_QUEUED_STR => BenchmarkJobStatus :: Queued ,
2008- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR => BenchmarkJobStatus :: InProgress {
2009- started_at : started_at. expect ( "started_at was null for an in progress job" ) ,
2010- collector_name : collector_name
2011- . expect ( "Collector is missing for an in progress job" ) ,
2012- } ,
2013- BENCHMARK_JOB_STATUS_FAILURE_STR | BENCHMARK_JOB_STATUS_SUCCESS_STR => {
2014- BenchmarkJobStatus :: Completed {
2015- started_at : started_at. expect ( "started_at was null for a finished job" ) ,
2016- completed_at : row. get :: < _ , DateTime < Utc > > ( 8 ) ,
2017- collector_name : collector_name
2018- . expect ( "Collector is missing for an in progress job" ) ,
2019- success : status == BENCHMARK_JOB_STATUS_SUCCESS_STR ,
2020- }
2021- }
2022- _ => panic ! ( "Invalid job status {status}" ) ,
2023- } ;
2024- let job = BenchmarkJob {
2025- id : row. get :: < _ , i32 > ( 0 ) as u32 ,
2026- request_tag : row. get :: < _ , String > ( 1 ) ,
2027- target : Target :: from_str ( row. get :: < _ , & str > ( 2 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2028- backend : CodegenBackend :: from_str ( row. get :: < _ , & str > ( 3 ) )
2029- . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2030- profile : Profile :: from_str ( row. get :: < _ , & str > ( 4 ) )
2031- . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2032- benchmark_set : BenchmarkSet ( row. get :: < _ , i32 > ( 5 ) as u32 ) ,
2033- created_at : row. get :: < _ , DateTime < Utc > > ( 6 ) ,
2034- status,
2035- deque_counter : row. get :: < _ , i32 > ( 10 ) as u32 ,
2036- kind : BenchmarkJobKind :: from_str ( row. get :: < _ , & str > ( 12 ) )
2037- . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2038- is_optional : row. get :: < _ , bool > ( 13 ) ,
2039- } ;
2047+ let job = parse_benchmark_job_from_row ( & row) ?;
20402048 request_to_jobs
20412049 . entry ( job. request_tag . clone ( ) )
20422050 . or_default ( )
@@ -2045,6 +2053,17 @@ where
20452053 Ok ( request_to_jobs)
20462054 }
20472055
2056+ async fn get_jobs_of_benchmark_requests (
2057+ & self ,
2058+ tags : & [ String ] ,
2059+ ) -> anyhow:: Result < Vec < BenchmarkJob > > {
2060+ let rows = self
2061+ . conn ( )
2062+ . query ( & self . statements ( ) . get_jobs_of_benchmark_requests , & [ & tags] )
2063+ . await ?;
2064+ rows. iter ( ) . map ( parse_benchmark_job_from_row) . collect ( )
2065+ }
2066+
20482067 async fn get_collector_configs ( & self ) -> anyhow:: Result < Vec < CollectorConfig > > {
20492068 let rows = self
20502069 . conn ( )
0 commit comments