feat: add retry loop for tool registration at startup
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 6m18s
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 6m18s
This commit is contained in:
@@ -234,9 +234,11 @@ public class ToolRegistryHeartbeatSender {
|
||||
public void registerAllTools() {
|
||||
if (registeredTools.isEmpty()) return;
|
||||
|
||||
new Thread(() -> {
|
||||
for (ToolMetadata tool : registeredTools) {
|
||||
registerTool(tool);
|
||||
}
|
||||
}, "McpToolRegistrationThread").start();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@@ -259,17 +261,31 @@ public class ToolRegistryHeartbeatSender {
|
||||
}
|
||||
|
||||
private void registerTool(ToolMetadata tool) {
|
||||
int maxRetries = 12;
|
||||
int delayMs = 10000;
|
||||
for (int i = 0; i < maxRetries; i++) {
|
||||
try {
|
||||
restClient.post()
|
||||
.uri(gatewayUrl + "/mcp/api/v1/registry/register")
|
||||
.header("Content-Type", "application/json")
|
||||
|
||||
.body(tool)
|
||||
.retrieve()
|
||||
.toBodilessEntity();
|
||||
log.info(" [HeartbeatSender] 툴 재등록 성공: {}", tool.getUid());
|
||||
log.info(" [HeartbeatSender] 툴 등록 성공: {}", tool.getUid());
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
log.error(" [HeartbeatSender] 툴 등록 실패: {}", ex.getMessage());
|
||||
if (i == maxRetries - 1) {
|
||||
log.error(" [HeartbeatSender] 툴 등록 최종 실패 ({}회 재시도): {}", maxRetries, ex.getMessage());
|
||||
} else {
|
||||
log.warn(" [HeartbeatSender] 툴 등록 실패, {}초 후 재시도... ({}/{}): {}", delayMs/1000, i+1, maxRetries, ex.getMessage());
|
||||
try {
|
||||
Thread.sleep(delayMs);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user