Миграции балансировка запросов идемпотентность graceful shutdown readines

This commit is contained in:
Dmitry
2026-10-27 21:33:13 +03:00
parent 6ddf0602ae
commit 36cbd70d37
13 changed files with 199 additions and 12 deletions
@@ -1,4 +1,25 @@
package org.example.config;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class GracefulShutdownListener {
private final ReadinessState state;
public GracefulShutdownListener(ReadinessState state) {
this.state = state;
}
@EventListener(ContextClosedEvent.class)
public void onClose(){
state.setReady(false);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@@ -1,4 +1,17 @@
package org.example.model;
package org.example.config;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicBoolean;
@Component
public class ReadinessState {
private final AtomicBoolean ready = new AtomicBoolean(true);
public boolean isReady() {
return ready.get();
}
public void setReady(boolean v) {
ready.set(v);
}
}