@@ -65,9 +65,18 @@ impl TargetConfigs {
65
65
}
66
66
67
67
pub async fn update ( & self , target : Target ) -> Result < ( ) , AlertError > {
68
- let id = target. id ;
69
- self . target_configs . write ( ) . await . insert ( id, target. clone ( ) ) ;
70
- let path = target_json_path ( & id) ;
68
+ let mut map = self . target_configs . write ( ) . await ;
69
+ if map. values ( ) . any ( |t| {
70
+ t. target == target. target
71
+ && t. timeout . interval == target. timeout . interval
72
+ && t. timeout . times == target. timeout . times
73
+ && t. id != target. id
74
+ } ) {
75
+ return Err ( AlertError :: DuplicateTargetConfig ) ;
76
+ }
77
+ map. insert ( target. id , target. clone ( ) ) ;
78
+
79
+ let path = target_json_path ( & target. id ) ;
71
80
72
81
let store = PARSEABLE . storage . get_object_store ( ) ;
73
82
let target_bytes = serde_json:: to_vec ( & target) ?;
@@ -146,21 +155,6 @@ pub struct Target {
146
155
}
147
156
148
157
impl Target {
149
- pub async fn validate ( & self ) -> Result < ( ) , AlertError > {
150
- // just check for liveness
151
- // what if the target is not live yet but is added by the user?
152
- let targets = TARGETS . list ( ) . await ?;
153
- for target in targets {
154
- if target. target == self . target
155
- && target. timeout . interval == self . timeout . interval
156
- && target. timeout . times == self . timeout . times
157
- {
158
- return Err ( AlertError :: DuplicateTargetConfig ) ;
159
- }
160
- }
161
- Ok ( ( ) )
162
- }
163
-
164
158
pub fn call ( & self , context : Context ) {
165
159
trace ! ( "target.call context- {context:?}" ) ;
166
160
let timeout = & self . timeout ;
0 commit comments