@@ -13,7 +13,7 @@ use tokio::{
1313 net:: UnixStream ,
1414} ;
1515
16- use protocol:: { Decoder , Message , Payload } ;
16+ use protocol:: { Decoder , FactoryInfo , Message , Payload } ;
1717
1818pub ( crate ) mod protocol;
1919pub ( crate ) mod server;
@@ -79,6 +79,7 @@ pub async fn main() -> Result<()> {
7979 l. cmd ( "store" , "access the job store" , cmd ! ( cmd_store) ) ?;
8080 l. cmd ( "address" , "manage IP addresses for this job" , cmd ! ( cmd_address) ) ?;
8181 l. cmd ( "process" , "manage background processes" , cmd ! ( cmd_process) ) ?;
82+ l. cmd ( "factory" , "factory information for this worker" , cmd ! ( cmd_factory) ) ?;
8283 l. hcmd ( "eng" , "for working on and testing buildomat" , cmd ! ( cmd_eng) ) ?;
8384
8485 sel ! ( l) . run ( ) . await
@@ -491,3 +492,89 @@ async fn cmd_process_start(mut l: Level<Stuff>) -> Result<()> {
491492 }
492493 }
493494}
495+
496+ async fn factory_info ( s : & mut Stuff ) -> Result < FactoryInfo > {
497+ let mout =
498+ Message { id : s. ids . next ( ) . unwrap ( ) , payload : Payload :: FactoryInfo } ;
499+
500+ match s. send_and_recv ( & mout) . await {
501+ Ok ( min) => {
502+ match min. payload {
503+ Payload :: Error ( e) => {
504+ /*
505+ * This request is purely local to the agent, so an
506+ * error is not something we should retry indefinitely.
507+ */
508+ bail ! ( "could not get factory info: {e}" ) ;
509+ }
510+ Payload :: FactoryInfoResult ( fi) => Ok ( fi) ,
511+ other => bail ! ( "unexpected response: {other:?}" ) ,
512+ }
513+ }
514+ Err ( e) => {
515+ /*
516+ * Requests to the agent are relatively simple and over a UNIX
517+ * socket; they should not fail. This implies something has
518+ * gone seriously wrong and it is unlikely that it will be fixed
519+ * without intervention. Don't retry.
520+ */
521+ bail ! ( "could not talk to the agent: {e}" ) ;
522+ }
523+ }
524+ }
525+
526+ async fn cmd_factory ( mut l : Level < Stuff > ) -> Result < ( ) > {
527+ l. context_mut ( ) . connect ( ) . await ?;
528+
529+ l. cmd (
530+ "name" ,
531+ "print the name of the factory that produced this worker" ,
532+ cmd ! ( cmd_factory_name) ,
533+ ) ?;
534+ l. cmd (
535+ "id" ,
536+ "print the unique ID of the factory that produced this worker" ,
537+ cmd ! ( cmd_factory_id) ,
538+ ) ?;
539+ l. cmd (
540+ "private" ,
541+ "print the factory-specific identifier for the underlying resource" ,
542+ cmd ! ( cmd_factory_private) ,
543+ ) ?;
544+
545+ sel ! ( l) . run ( ) . await
546+ }
547+
548+ async fn cmd_factory_id ( mut l : Level < Stuff > ) -> Result < ( ) > {
549+ no_args ! ( l) ;
550+
551+ let fi = factory_info ( l. context_mut ( ) ) . await ?;
552+
553+ println ! ( "{}" , fi. id) ;
554+
555+ Ok ( ( ) )
556+ }
557+
558+ async fn cmd_factory_name ( mut l : Level < Stuff > ) -> Result < ( ) > {
559+ no_args ! ( l) ;
560+
561+ let fi = factory_info ( l. context_mut ( ) ) . await ?;
562+
563+ println ! ( "{}" , fi. name) ;
564+
565+ Ok ( ( ) )
566+ }
567+
568+ async fn cmd_factory_private ( mut l : Level < Stuff > ) -> Result < ( ) > {
569+ no_args ! ( l) ;
570+
571+ let fi = factory_info ( l. context_mut ( ) ) . await ?;
572+
573+ let Some ( fp) = & fi. private else {
574+ bail ! ( "factory private info not available" ) ;
575+ } ;
576+
577+ println ! ( "{fp}" ) ;
578+
579+ Ok ( ( ) )
580+ }
0 commit comments