1- use crate :: flow_definition:: Reader ;
1+ use crate :: { flow_definition:: Reader , flow_service:: retry:: create_channel_with_retry} ;
2+ use tonic:: transport:: Channel ;
23use tucana:: {
34 aquila:: {
45 DataTypeUpdateRequest , FlowTypeUpdateRequest , RuntimeFunctionDefinitionUpdateRequest ,
@@ -9,18 +10,20 @@ use tucana::{
910 shared:: { DefinitionDataType as DataType , FlowType , RuntimeFunctionDefinition } ,
1011} ;
1112
13+ mod retry;
14+
1215pub struct FlowUpdateService {
13- aquila_url : String ,
1416 data_types : Vec < DataType > ,
1517 runtime_definitions : Vec < RuntimeFunctionDefinition > ,
1618 flow_types : Vec < FlowType > ,
19+ channel : Channel ,
1720}
1821
1922impl FlowUpdateService {
2023 /// Create a new FlowUpdateService instance from an Aquila URL and a definition path.
2124 ///
2225 /// This will read the definition files from the given path and initialize the service with the data types, runtime definitions, and flow types.
23- pub fn from_url ( aquila_url : String , definition_path : & str ) -> Self {
26+ pub async fn from_url ( aquila_url : String , definition_path : & str ) -> Self {
2427 let mut data_types = Vec :: new ( ) ;
2528 let mut runtime_definitions = Vec :: new ( ) ;
2629 let mut flow_types = Vec :: new ( ) ;
@@ -41,11 +44,13 @@ impl FlowUpdateService {
4144 runtime_definitions. append ( & mut feature. functions . clone ( ) ) ;
4245 }
4346
47+ let channel = create_channel_with_retry ( "Aquila" , aquila_url) . await ;
48+
4449 Self {
45- aquila_url,
4650 data_types,
4751 runtime_definitions,
4852 flow_types,
53+ channel,
4954 }
5055 }
5156
@@ -80,17 +85,7 @@ impl FlowUpdateService {
8085 }
8186
8287 log:: info!( "Updating the current DataTypes!" ) ;
83- let mut client = match DataTypeServiceClient :: connect ( self . aquila_url . clone ( ) ) . await {
84- Ok ( client) => {
85- log:: info!( "Successfully connected to the DataTypeService" ) ;
86- client
87- }
88- Err ( err) => {
89- log:: error!( "Failed to connect to the DataTypeService: {:?}" , err) ;
90- return ;
91- }
92- } ;
93-
88+ let mut client = DataTypeServiceClient :: new ( self . channel . clone ( ) ) ;
9489 let request = DataTypeUpdateRequest {
9590 data_types : self . data_types . clone ( ) ,
9691 } ;
@@ -115,21 +110,7 @@ impl FlowUpdateService {
115110 }
116111
117112 log:: info!( "Updating the current RuntimeDefinitions!" ) ;
118- let mut client =
119- match RuntimeFunctionDefinitionServiceClient :: connect ( self . aquila_url . clone ( ) ) . await {
120- Ok ( client) => {
121- log:: info!( "Connected to RuntimeFunctionDefinitionService" ) ;
122- client
123- }
124- Err ( err) => {
125- log:: error!(
126- "Failed to connect to RuntimeFunctionDefinitionService: {:?}" ,
127- err
128- ) ;
129- return ;
130- }
131- } ;
132-
113+ let mut client = RuntimeFunctionDefinitionServiceClient :: new ( self . channel . clone ( ) ) ;
133114 let request = RuntimeFunctionDefinitionUpdateRequest {
134115 runtime_functions : self . runtime_definitions . clone ( ) ,
135116 } ;
@@ -154,17 +135,7 @@ impl FlowUpdateService {
154135 }
155136
156137 log:: info!( "Updating the current FlowTypes!" ) ;
157- let mut client = match FlowTypeServiceClient :: connect ( self . aquila_url . clone ( ) ) . await {
158- Ok ( client) => {
159- log:: info!( "Connected to FlowTypeService!" ) ;
160- client
161- }
162- Err ( err) => {
163- log:: error!( "Failed to connect to FlowTypeService: {:?}" , err) ;
164- return ;
165- }
166- } ;
167-
138+ let mut client = FlowTypeServiceClient :: new ( self . channel . clone ( ) ) ;
168139 let request = FlowTypeUpdateRequest {
169140 flow_types : self . flow_types . clone ( ) ,
170141 } ;
0 commit comments