@@ -5,7 +5,8 @@ use crate::{
55 BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkRequestType ,
66 BenchmarkSet , CodegenBackend , CollectionId , CollectorConfig , Commit , CommitType ,
77 CompileBenchmark , Date , Index , Profile , QueuedCommit , Scenario , Target ,
8- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR , BENCHMARK_JOB_STATUS_QUEUED_STR ,
8+ BENCHMARK_JOB_STATUS_FAILURE_STR , BENCHMARK_JOB_STATUS_IN_PROGRESS_STR ,
9+ BENCHMARK_JOB_STATUS_QUEUED_STR , BENCHMARK_JOB_STATUS_SUCCESS_STR ,
910 BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
1011 BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR , BENCHMARK_REQUEST_STATUS_COMPLETED_STR ,
1112 BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR , BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR ,
@@ -1887,6 +1888,82 @@ where
18871888 }
18881889 }
18891890 }
1891+
1892+ async fn mark_benchmark_request_as_completed (
1893+ & self ,
1894+ benchmark_request : & mut BenchmarkRequest ,
1895+ ) -> anyhow:: Result < bool > {
1896+ anyhow:: ensure!(
1897+ benchmark_request. tag( ) . is_some( ) ,
1898+ "Benchmark request has no tag"
1899+ ) ;
1900+ anyhow:: ensure!(
1901+ benchmark_request. status == BenchmarkRequestStatus :: InProgress ,
1902+ "Can only mark benchmark request whos status is in_progress as complete"
1903+ ) ;
1904+
1905+ // Find if the benchmark is completed and update it's status to completed
1906+ // in one SQL block
1907+ let row = self
1908+ . conn ( )
1909+ . query_opt (
1910+ "
1911+ UPDATE
1912+ benchmark_request
1913+ SET
1914+ status = $1,
1915+ completed_at = NOW()
1916+ WHERE
1917+ banchmark_request.tag = $2
1918+ AND benchmark_request.status != $1
1919+ AND NOT EXISTS (
1920+ SELECT
1921+ 1
1922+ FROM
1923+ job_queue
1924+ WHERE
1925+ request_tag = benchmark_request.tag
1926+ AND status NOT IN ($3, $4)
1927+ )
1928+ AND (
1929+ benchmark_request.parent_sha IS NULL
1930+ OR NOT EXISTS (
1931+ SELECT
1932+ 1
1933+ FROM
1934+ job_queue
1935+ JOIN
1936+ benchmark_request AS parent_request
1937+ ON
1938+ parent_request.tag = benchmark_request.parent_tag
1939+ WHERE
1940+ job_queue.request_tag = parent_request.tag
1941+ AND job_queue.status NOT IN ($3, $4)
1942+ )
1943+ )
1944+ RETURNING
1945+ benchmark_request.completed_at;
1946+ " ,
1947+ & [
1948+ & BENCHMARK_REQUEST_STATUS_COMPLETED_STR ,
1949+ & benchmark_request. tag ( ) ,
1950+ & BENCHMARK_JOB_STATUS_SUCCESS_STR ,
1951+ & BENCHMARK_JOB_STATUS_FAILURE_STR ,
1952+ ] ,
1953+ )
1954+ . await
1955+ . context ( "Failed to mark benchmark_request as completed" ) ?;
1956+ // The affected id is returned by the query thus we can use the row's
1957+ // presence to determine if the request was marked as completed
1958+ if let Some ( row) = row {
1959+ let completed_at = row. get :: < _ , DateTime < Utc > > ( 0 ) ;
1960+ // Also mutate our object
1961+ benchmark_request. status = BenchmarkRequestStatus :: Completed { completed_at } ;
1962+ Ok ( true )
1963+ } else {
1964+ Ok ( false )
1965+ }
1966+ }
18901967}
18911968
18921969fn parse_artifact_id ( ty : & str , sha : & str , date : Option < DateTime < Utc > > ) -> ArtifactId {
0 commit comments