|
| 1 | +package net.brightroom.example.customrolloutstrategy; |
| 2 | + |
| 3 | +import java.time.LocalTime; |
| 4 | +import java.time.ZoneId; |
| 5 | +import net.brightroom.endpointgate.core.context.EndpointGateContext; |
| 6 | +import net.brightroom.endpointgate.reactive.core.rollout.DefaultReactiveRolloutStrategy; |
| 7 | +import net.brightroom.endpointgate.reactive.core.rollout.ReactiveRolloutStrategy; |
| 8 | +import org.springframework.context.annotation.Profile; |
| 9 | +import org.springframework.stereotype.Component; |
| 10 | +import reactor.core.publisher.Mono; |
| 11 | + |
| 12 | +@Component |
| 13 | +@Profile("time-based") |
| 14 | +public class TimeBasedReactiveRolloutStrategy implements ReactiveRolloutStrategy { |
| 15 | + |
| 16 | + private static final LocalTime BUSINESS_START = LocalTime.of(9, 0); |
| 17 | + private static final LocalTime BUSINESS_END = LocalTime.of(17, 0); |
| 18 | + private static final ZoneId ZONE = ZoneId.of("Asia/Tokyo"); |
| 19 | + |
| 20 | + private final DefaultReactiveRolloutStrategy defaultStrategy = |
| 21 | + new DefaultReactiveRolloutStrategy(); |
| 22 | + |
| 23 | + @Override |
| 24 | + public Mono<Boolean> isInRollout(String gateId, EndpointGateContext context, int percentage) { |
| 25 | + LocalTime now = LocalTime.now(ZONE); |
| 26 | + if (now.isBefore(BUSINESS_START)) { |
| 27 | + return Mono.just(false); |
| 28 | + } |
| 29 | + if (!now.isBefore(BUSINESS_END)) { |
| 30 | + return Mono.just(false); |
| 31 | + } |
| 32 | + return defaultStrategy.isInRollout(gateId, context, percentage); |
| 33 | + } |
| 34 | +} |
0 commit comments