@@ -57,42 +57,29 @@ impl InstanceProvider {
57
57
template_option : Option < & str > ,
58
58
state_option : Option < & EpsilonState > ,
59
59
) -> Result < Vec < Arc < EpsilonInstance > > , EpsilonError > {
60
- let mut instances = self . epsilon_controller . get_epsilon_instance_store ( ) . state ( ) ;
60
+ let instances = self . epsilon_controller . get_epsilon_instance_store ( ) . state ( ) ;
61
61
62
62
for instance in & instances {
63
- let name = instance. get_name ( ) ;
63
+ instance. status . as_ref ( ) . ok_or ( EpsilonError :: RetrieveInstanceError ) ?;
64
+ }
64
65
65
- let condition = await_condition (
66
- self . epsilon_controller . get_epsilon_instance_api ( ) ,
67
- & name,
68
- move |object : Option < & EpsilonInstance > | {
69
- object. map_or ( false , |instance| instance. status . is_some ( ) )
70
- } ,
71
- ) ;
66
+ Ok ( instances. into_iter ( )
67
+ . filter ( |instance| {
68
+ let status = instance. status . as_ref ( ) . unwrap ( ) ;
72
69
73
- let _ = tokio:: time:: timeout ( std:: time:: Duration :: from_secs ( 5 ) , condition) . await ?;
74
- }
70
+ let condition1 = status. t == * instance_type;
71
+
72
+ let condition2 = if let Some ( template_name) = template_option {
73
+ instance. spec . template == template_name
74
+ } else { true } ;
75
+
76
+ let condition3 = if let Some ( state) = state_option {
77
+ status. state == * state
78
+ } else { true } ;
75
79
76
- instances = instances
77
- . into_iter ( )
78
- . filter ( |instance| instance. status . as_ref ( ) . unwrap ( ) . t == * instance_type)
79
- . collect ( ) ;
80
-
81
- if let Some ( template_name) = template_option {
82
- instances = instances
83
- . into_iter ( )
84
- . filter ( |instance| instance. spec . template == template_name)
85
- . collect ( ) ;
86
- } ;
87
-
88
- if let Some ( state) = state_option {
89
- instances = instances
90
- . into_iter ( )
91
- . filter ( |instance| instance. status . as_ref ( ) . unwrap ( ) . state == * state)
92
- . collect ( ) ;
93
- } ;
94
-
95
- Ok ( instances)
80
+ condition1 && condition2 && condition3
81
+ } )
82
+ . collect ( ) )
96
83
}
97
84
98
85
pub async fn enable_in_game_instance ( & self , name : & str ) -> Result < ( ) , EpsilonError > {
0 commit comments