@@ -12,6 +12,7 @@ use std::marker::PhantomData;
1212use std:: path:: { Path , PathBuf } ;
1313use std:: process;
1414use std:: process:: Command ;
15+ use std:: str:: FromStr ;
1516use std:: time:: Duration ;
1617use std:: { str, time:: Instant } ;
1718
@@ -666,6 +667,37 @@ enum Commands {
666667 /// The name of the modified artifact to be compared.
667668 modified : Option < String > ,
668669 } ,
670+
671+ /// Registers a collector in the database
672+ AddCollector {
673+ #[ command( flatten) ]
674+ db : DbOption ,
675+
676+ #[ arg( long) ]
677+ collector_name : String ,
678+
679+ #[ arg( long) ]
680+ target : String ,
681+
682+ #[ arg( long) ]
683+ is_active : bool ,
684+
685+ #[ arg( long) ]
686+ benchmark_set : u32 ,
687+ } ,
688+
689+ /// Polls the job queue for work to benchmark
690+ DequeueJob {
691+ /// The unique identifier for the collector
692+ #[ arg( long) ]
693+ collector_name : String ,
694+
695+ #[ arg( long) ]
696+ target : String ,
697+
698+ #[ command( flatten) ]
699+ db : DbOption ,
700+ } ,
669701}
670702
671703#[ derive( Debug , clap:: Parser ) ]
@@ -1266,6 +1298,63 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
12661298 rt. block_on ( compare_artifacts ( conn, metric, base, modified) ) ?;
12671299 Ok ( 0 )
12681300 }
1301+
1302+ Commands :: AddCollector {
1303+ db,
1304+ collector_name,
1305+ target,
1306+ is_active,
1307+ benchmark_set,
1308+ } => {
1309+ let pool = Pool :: open ( & db. db ) ;
1310+ let rt = build_async_runtime ( ) ;
1311+ let conn = rt. block_on ( pool. connection ( ) ) ;
1312+
1313+ let target = database:: Target :: from_str ( & target) . map_err ( |e| anyhow:: anyhow!( e) ) ?;
1314+ rt. block_on ( conn. add_collector_config (
1315+ & collector_name,
1316+ & target,
1317+ benchmark_set,
1318+ is_active,
1319+ ) ) ?;
1320+ Ok ( 0 )
1321+ }
1322+
1323+ Commands :: DequeueJob {
1324+ collector_name,
1325+ db,
1326+ target,
1327+ } => {
1328+ let pool = Pool :: open ( & db. db ) ;
1329+ let rt = build_async_runtime ( ) ;
1330+ let conn = rt. block_on ( pool. connection ( ) ) ;
1331+
1332+ // Obtain the configuration and validate that it matches the
1333+ // collector's setup
1334+ let collector_config: database:: CollectorConfig =
1335+ rt. block_on ( conn. get_collector_config ( & collector_name) ) ?;
1336+
1337+ let collector_target = collector_config. target ( ) ;
1338+ if collector_target. as_str ( ) != target {
1339+ panic ! (
1340+ "Mismatching target for collector expected `{collector_target}` got `{target}`"
1341+ ) ;
1342+ }
1343+
1344+ // Dequeue a job
1345+ let benchmark_job = rt. block_on ( conn. dequeue_benchmark_job (
1346+ & collector_name,
1347+ collector_config. target ( ) ,
1348+ collector_config. benchmark_set ( ) ,
1349+ ) ) ?;
1350+
1351+ if let Some ( benchmark_job) = benchmark_job {
1352+ // TODO; process the job
1353+ println ! ( "{:?}" , benchmark_job) ;
1354+ }
1355+
1356+ Ok ( 0 )
1357+ }
12691358 }
12701359}
12711360
0 commit comments