|
18 | 18 | import ai.wanaku.capabilities.sdk.api.discovery.RegistrationManager; |
19 | 19 | import ai.wanaku.capabilities.sdk.api.exceptions.WanakuException; |
20 | 20 | import ai.wanaku.capabilities.sdk.api.types.WanakuResponse; |
21 | | -import ai.wanaku.capabilities.sdk.api.types.discovery.ServiceState; |
22 | 21 | import ai.wanaku.capabilities.sdk.api.types.providers.ServiceTarget; |
23 | 22 | import ai.wanaku.capabilities.sdk.data.files.InstanceDataManager; |
24 | 23 | import ai.wanaku.capabilities.sdk.data.files.ServiceEntry; |
@@ -175,11 +174,7 @@ private int waitAndRetry(String serviceName, Exception e, int currentRetries, in |
175 | 174 | */ |
176 | 175 | @Override |
177 | 176 | public void register() { |
178 | | - if (isRegistered()) { |
179 | | - if (config.isPingEnabled()) { |
180 | | - ping(); |
181 | | - } |
182 | | - } else { |
| 177 | + if (!isRegistered()) { |
183 | 178 | tryRegistering(); |
184 | 179 | } |
185 | 180 | } |
@@ -215,82 +210,6 @@ public void deregister() { |
215 | 210 | } |
216 | 211 | } |
217 | 212 |
|
218 | | - /** |
219 | | - * Sends a ping to the Wanaku Discovery API to keep the service registration alive. |
220 | | - */ |
221 | | - @Override |
222 | | - public void ping() { |
223 | | - if (!config.isPingEnabled()) { |
224 | | - return; |
225 | | - } |
226 | | - |
227 | | - if (target != null && target.getId() != null) { |
228 | | - LOG.trace("Pinging router ..."); |
229 | | - try { |
230 | | - // Assuming client.ping(target.getId()) exists and returns HttpResponse<String> |
231 | | - final HttpResponse<String> response = client.ping(target.getId()); |
232 | | - final int status = response.statusCode(); |
233 | | - runCallBack(c -> c.onPing(this, target, status)); |
234 | | - } catch (Exception e) { |
235 | | - if (LOG.isDebugEnabled()) { |
236 | | - LOG.warn("Pinging router failed with {}", e.getMessage(), e); |
237 | | - } else { |
238 | | - LOG.warn("Pinging router failed with {}", e.getMessage()); |
239 | | - } |
240 | | - } |
241 | | - } |
242 | | - } |
243 | | - |
244 | | - /** |
245 | | - * Updates the service's state to 'unhealthy' with a given reason. |
246 | | - * |
247 | | - * @param reason The reason for the service being unhealthy. |
248 | | - */ |
249 | | - @Override |
250 | | - public void lastAsFail(String reason) { |
251 | | - if (target.getId() == null) { |
252 | | - LOG.warn("Trying to update the state of an unknown service {}", target.getServiceName()); |
253 | | - return; |
254 | | - } |
255 | | - |
256 | | - try { |
257 | | - final HttpResponse<String> response = client.updateState(target.getId(), ServiceState.newUnhealthy(reason)); |
258 | | - if (response.statusCode() != 200) { |
259 | | - LOG.error("Could not update the state of an service {} ({})", target.getServiceName(), target.getId()); |
260 | | - } |
261 | | - } catch (Exception e) { |
262 | | - if (LOG.isDebugEnabled()) { |
263 | | - LOG.warn("Updating last status failed with {}", e.getMessage(), e); |
264 | | - } else { |
265 | | - LOG.warn("Updating last status failed with {}", e.getMessage()); |
266 | | - } |
267 | | - } |
268 | | - } |
269 | | - |
270 | | - /** |
271 | | - * Updates the service's state to 'healthy'. |
272 | | - */ |
273 | | - @Override |
274 | | - public void lastAsSuccessful() { |
275 | | - if (target.getId() == null) { |
276 | | - LOG.warn("Trying to update the state of an unknown service {}", target.getServiceName()); |
277 | | - return; |
278 | | - } |
279 | | - |
280 | | - try { |
281 | | - final HttpResponse<String> response = client.updateState(target.getId(), ServiceState.newHealthy()); |
282 | | - if (response.statusCode() != 200) { |
283 | | - LOG.error("Could not update the state of an service {} ({})", target.getServiceName(), target.getId()); |
284 | | - } |
285 | | - } catch (Exception e) { |
286 | | - if (LOG.isDebugEnabled()) { |
287 | | - LOG.warn("Updating last status failed with {}", e.getMessage(), e); |
288 | | - } else { |
289 | | - LOG.warn("Updating last status failed with {}", e.getMessage()); |
290 | | - } |
291 | | - } |
292 | | - } |
293 | | - |
294 | 213 | /** |
295 | 214 | * Starts the scheduled registration task, which periodically calls the {@link #register()} method. |
296 | 215 | * The initial delay and period are configured via {@link RegistrationConfig}. |
|
0 commit comments