@@ -384,6 +384,9 @@ static MIGRATIONS: &[&str] = &[
384384 r#"
385385 ALTER TABLE benchmark_request ADD COLUMN duration_ms INTEGER NULL;
386386 "# ,
387+ r#"
388+ ALTER TABLE collector_config ADD COLUMN commit_sha TEXT NULL;
389+ "# ,
387390] ;
388391
389392#[ async_trait:: async_trait]
@@ -1732,28 +1735,33 @@ where
17321735 is_active,
17331736 last_heartbeat_at : row. get :: < _ , DateTime < Utc > > ( 0 ) ,
17341737 date_added : row. get :: < _ , DateTime < Utc > > ( 1 ) ,
1738+ commit_sha : None ,
17351739 } ;
17361740 Ok ( collector_config)
17371741 }
17381742
1739- async fn get_collector_config (
1743+ async fn start_collector (
17401744 & self ,
17411745 collector_name : & str ,
1746+ commit_sha : & str ,
17421747 ) -> anyhow:: Result < Option < CollectorConfig > > {
17431748 let row = self
17441749 . conn ( )
17451750 . query_opt (
1746- "SELECT
1751+ "
1752+ UPDATE collector_config
1753+ SET
1754+ last_heartbeat_at = NOW(),
1755+ commit_sha = $2
1756+ WHERE
1757+ name = $1
1758+ RETURNING
17471759 target,
17481760 benchmark_set,
17491761 is_active,
17501762 last_heartbeat_at,
1751- date_added
1752- FROM
1753- collector_config
1754- WHERE
1755- name = $1;" ,
1756- & [ & collector_name] ,
1763+ date_added" ,
1764+ & [ & collector_name, & commit_sha] ,
17571765 )
17581766 . await ?;
17591767
@@ -1767,6 +1775,7 @@ where
17671775 is_active : row. get :: < _ , bool > ( 2 ) ,
17681776 last_heartbeat_at : row. get :: < _ , DateTime < Utc > > ( 3 ) ,
17691777 date_added : row. get :: < _ , DateTime < Utc > > ( 4 ) ,
1778+ commit_sha : Some ( commit_sha. to_string ( ) ) ,
17701779 } )
17711780 } )
17721781 . transpose ( ) ?)
@@ -2180,25 +2189,29 @@ where
21802189 benchmark_set,
21812190 is_active,
21822191 last_heartbeat_at,
2183- date_added
2192+ date_added,
2193+ commit_sha
21842194 FROM
21852195 collector_config;" ,
21862196 & [ ] ,
21872197 )
21882198 . await ?;
21892199
2190- let mut configs = vec ! [ ] ;
2191- for row in rows {
2192- let config = CollectorConfig {
2193- name : row. get :: < _ , String > ( 0 ) ,
2194- target : Target :: from_str ( row. get :: < _ , & str > ( 1 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2195- benchmark_set : BenchmarkSet ( row. get :: < _ , i32 > ( 2 ) as u32 ) ,
2196- is_active : row. get :: < _ , bool > ( 3 ) ,
2197- last_heartbeat_at : row. get :: < _ , DateTime < Utc > > ( 4 ) ,
2198- date_added : row. get :: < _ , DateTime < Utc > > ( 5 ) ,
2199- } ;
2200- configs. push ( config) ;
2201- }
2200+ let configs = rows
2201+ . into_iter ( )
2202+ . map ( |row| {
2203+ Ok ( CollectorConfig {
2204+ name : row. get :: < _ , String > ( 0 ) ,
2205+ target : Target :: from_str ( row. get :: < _ , & str > ( 1 ) )
2206+ . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2207+ benchmark_set : BenchmarkSet ( row. get :: < _ , i32 > ( 2 ) as u32 ) ,
2208+ is_active : row. get :: < _ , bool > ( 3 ) ,
2209+ last_heartbeat_at : row. get :: < _ , DateTime < Utc > > ( 4 ) ,
2210+ date_added : row. get :: < _ , DateTime < Utc > > ( 5 ) ,
2211+ commit_sha : row. get :: < _ , Option < String > > ( 6 ) ,
2212+ } )
2213+ } )
2214+ . collect :: < anyhow:: Result < Vec < _ > > > ( ) ?;
22022215
22032216 Ok ( configs)
22042217 }
0 commit comments