mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
fix(agent): run system exit after agent launch failed
This commit is contained in:
@@ -6,9 +6,12 @@ import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Agent.newAgent(Main.class)
|
boolean launched = Agent.newAgent(Main.class)
|
||||||
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
|
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
|
||||||
.addConfigurable(new VectorClientRegistry())
|
.addConfigurable(new VectorClientRegistry())
|
||||||
.launch();
|
.launch();
|
||||||
|
if (!launched) {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import java.time.ZonedDateTime
|
|||||||
|
|
||||||
object AgentContext {
|
object AgentContext {
|
||||||
|
|
||||||
|
private val log = LoggerFactory.getLogger(this::class.java)
|
||||||
|
|
||||||
private val _modules =
|
private val _modules =
|
||||||
mutableMapOf<String, ModuleContextData<AbstractAgentModule>>()
|
mutableMapOf<String, ModuleContextData<AbstractAgentModule>>()
|
||||||
|
|
||||||
@@ -156,7 +158,6 @@ object AgentContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun trigger(hooks: List<ShutdownHookDesc>, instances: Instances) {
|
fun trigger(hooks: List<ShutdownHookDesc>, instances: Instances) {
|
||||||
val log = LoggerFactory.getLogger(AgentContext::class.java)
|
|
||||||
hooks.sortedBy { it.order }
|
hooks.sortedBy { it.order }
|
||||||
.forEach {
|
.forEach {
|
||||||
try {
|
try {
|
||||||
@@ -168,7 +169,6 @@ object AgentContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun triggerLifecycleHooks(hooks: List<LifecycleShutdownHookDesc>) {
|
fun triggerLifecycleHooks(hooks: List<LifecycleShutdownHookDesc>) {
|
||||||
val log = LoggerFactory.getLogger(AgentContext::class.java)
|
|
||||||
hooks.sortedBy { it.order }
|
hooks.sortedBy { it.order }
|
||||||
.forEach {
|
.forEach {
|
||||||
try {
|
try {
|
||||||
@@ -180,6 +180,7 @@ object AgentContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(Thread {
|
Runtime.getRuntime().addShutdownHook(Thread {
|
||||||
|
log.info("Shutdown hooks triggering...")
|
||||||
val instances = computeInstances()
|
val instances = computeInstances()
|
||||||
triggerLifecycleHooks(preShutdownHooks)
|
triggerLifecycleHooks(preShutdownHooks)
|
||||||
shutdownHooks[ShutdownHookDesc.Type.RUNNING]?.let { trigger(it, instances) }
|
shutdownHooks[ShutdownHookDesc.Type.RUNNING]?.let { trigger(it, instances) }
|
||||||
@@ -188,6 +189,7 @@ object AgentContext {
|
|||||||
shutdownHooks[ShutdownHookDesc.Type.SUB]?.let { trigger(it, instances) }
|
shutdownHooks[ShutdownHookDesc.Type.SUB]?.let { trigger(it, instances) }
|
||||||
shutdownHooks[ShutdownHookDesc.Type.CAPABILITY]?.let { trigger(it, instances) }
|
shutdownHooks[ShutdownHookDesc.Type.CAPABILITY]?.let { trigger(it, instances) }
|
||||||
triggerLifecycleHooks(postShutdownHooks)
|
triggerLifecycleHooks(postShutdownHooks)
|
||||||
|
log.info("Shutdown hooks triggered...")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user