I have an application based on Spring WebFlux and Reactor. Application starts everyday on a schedule and loads statistics. But there is also available a manual launch option through controller. So if my app is still running and somebody wants to start app through controller, conflicts may happen. Thats why I need a tool to detect if my Reactor chain is still running or not. If yes, then throw exception (or maybe just message) and app should ignore call from controller and continue load statistics instead of being interrupted. Is there any tools ready to be applied for this task? There is a simple boolean checkbox solution, but does WebFlux/Reactor provides this kind of feature? Reactor chain looks like:
Mono.fromRunnable(() -> { log.info("Scheduled update has been started."); service1.doSmth1(); }) .then(Mono.fromRunnable(() -> log.info("Scheduled names collecting has been started."))) .then(service2.doSmth2()) .then(Mono.fromRunnable(() -> log.info("Scheduled orders collectins has been started"))) .then(service3.doSmth3()) .then(Mono.fromRunnable(() -> log.info("Scheduled update has finished."))) .then() .doOnSuccess(a -> log.info("Finished updating stats.")) .doOnError(throwable -> log.error("{}", throwable.getMessage()));
Advertisement
Answer
There is no such built-in feature. An AtomicBoolean
state could be used here, which can be updated at the end of the chain by adding a doFinally(signal -> isRunningFlag.compareAndSet(true, false))
.