fix(core): keep web up during graceful shutdown

The `@PreDestroy` hook is triggered very late in the lifecycle.

Started the graceful clean using the global `ShutdownEvent`.
This commit is contained in:
yuri1969
2025-10-08 23:05:15 +02:00
committed by Florian Hussonnois
parent 5ec869b1cc
commit 33628107c3

View File

@@ -0,0 +1,34 @@
package io.kestra.cli.listeners;
import io.kestra.worker.DefaultWorker;
import io.micronaut.context.event.ApplicationEventListener;
import io.micronaut.context.event.ShutdownEvent;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;
/**
* Global application shutdown handler.
* This handler gets effectively invoked before {@link jakarta.annotation.PreDestroy} does.
*/
@Slf4j
public class ShutdownListener implements ApplicationEventListener<ShutdownEvent> {
@Inject
DefaultWorker worker;
/**
* {@inheritDoc}
**/
@Override
public void onApplicationEvent(ShutdownEvent event) {
log.debug("Shutdown event received");
worker.close();
}
/**
* {@inheritDoc}
**/
@Override
public boolean supports(ShutdownEvent event) {
return ApplicationEventListener.super.supports(event);
}
}