fix: cap concurrent shadow planning
This commit is contained in:
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Component
|
||||
public class ShadowObservationGateway {
|
||||
@@ -12,6 +13,7 @@ public class ShadowObservationGateway {
|
||||
|
||||
private final ShadowObservationProperties properties;
|
||||
private final ShadowPlanningEngine engine;
|
||||
private final AtomicBoolean planning = new AtomicBoolean();
|
||||
|
||||
public ShadowObservationGateway(ShadowObservationProperties properties, ShadowPlanningEngine engine) {
|
||||
this.properties = Objects.requireNonNull(properties, "properties");
|
||||
@@ -22,11 +24,16 @@ public class ShadowObservationGateway {
|
||||
if (!properties.isEnabled() || engine == null) {
|
||||
return InboundShadowObservation.empty();
|
||||
}
|
||||
if (!planning.compareAndSet(false, true)) {
|
||||
return InboundShadowObservation.empty();
|
||||
}
|
||||
try {
|
||||
return engine.planInbound(taskNo, trayNo);
|
||||
} catch (RuntimeException exception) {
|
||||
LOG.warn("Shadow inbound planning failed open for task {}: {}", taskNo, exception.getMessage());
|
||||
return InboundShadowObservation.empty();
|
||||
} finally {
|
||||
planning.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +41,17 @@ public class ShadowObservationGateway {
|
||||
if (!properties.isEnabled() || engine == null) {
|
||||
return OutboundShadowObservation.empty();
|
||||
}
|
||||
if (!planning.compareAndSet(false, true)) {
|
||||
return OutboundShadowObservation.empty();
|
||||
}
|
||||
try {
|
||||
return engine.planProjectOutbound(stockoutDetailId);
|
||||
} catch (RuntimeException exception) {
|
||||
LOG.warn("Shadow outbound planning failed open for detail {}: {}",
|
||||
stockoutDetailId, exception.getMessage());
|
||||
return OutboundShadowObservation.empty();
|
||||
} finally {
|
||||
planning.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +59,17 @@ public class ShadowObservationGateway {
|
||||
if (!properties.isEnabled() || engine == null) {
|
||||
return OutboundShadowObservation.empty();
|
||||
}
|
||||
if (!planning.compareAndSet(false, true)) {
|
||||
return OutboundShadowObservation.empty();
|
||||
}
|
||||
try {
|
||||
return engine.planExactStockOutbound(stockoutDetailId, stockId);
|
||||
} catch (RuntimeException exception) {
|
||||
LOG.warn("Shadow exact-stock planning failed open for detail {} stock {}: {}",
|
||||
stockoutDetailId, stockId, exception.getMessage());
|
||||
return OutboundShadowObservation.empty();
|
||||
} finally {
|
||||
planning.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user