Skip to content

Commit f55fdea

Browse files
committed
refactor: clean up
1 parent c4de7cc commit f55fdea

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

backend/src/main/java/ch/xxx/trader/adapter/cron/ScheduledTask.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ private void insertBsQuote(String currPair) {
112112
// log.info(res.toString());
113113
return res;
114114
}).timeout(Duration.ofSeconds(5L)).onErrorResume(ex -> {
115-
exceptionLogged.set(true);
116-
LOG.warn(String.format("Bitstamp data request for %s failed", currPair), ex);
115+
exceptionLogged.set(this.logRequestFailed("Bitstamp", currPair, start, ex));
117116
return Mono.empty();
118117
}).subscribeOn(this.mongoImportScheduler);
119118
Disposable subscribe = null;
@@ -135,6 +134,11 @@ private void logDuration(String source, String currPair, LocalTime start) {
135134
}
136135
}
137136

137+
private boolean logRequestFailed(String source, String currPair, LocalTime start, Throwable ex) {
138+
LOG.warn(String.format("%s data request for %s failed", source, currPair), ex);
139+
return true;
140+
}
141+
138142
@Async("clientTaskExecutor")
139143
@Scheduled(fixedRate = 60000, initialDelay = 6000)
140144
@SchedulerLock(name = "BitstampQuoteETH_scheduledTask", lockAtLeastFor = "PT50S", lockAtMostFor = "PT55S")
@@ -179,8 +183,7 @@ public void insertCoinbaseQuote() {
179183
// log.info(resp2.getRates().toString());
180184
return Mono.just(resp2.getRates());
181185
}).timeout(Duration.ofSeconds(5L)).onErrorResume(ex -> {
182-
exceptionLogged.set(true);
183-
LOG.warn("Coinbase data request failed", ex);
186+
exceptionLogged.set(this.logRequestFailed("Coinbase", currPair, start, ex));
184187
return Mono.empty();
185188
}).subscribeOn(this.mongoImportScheduler);
186189
Disposable subscribe = request.flatMap(myQuote -> this.coinbaseService.insertQuote(Mono.just(myQuote))
@@ -210,8 +213,7 @@ public void insertItbitUsdQuote() {
210213
// log.info(res.toString());
211214
return res;
212215
}).map(paxosQuote -> this.convert(paxosQuote)).timeout(Duration.ofSeconds(5L)).onErrorResume(ex -> {
213-
exceptionLogged.set(true);
214-
LOG.warn(String.format("Ibit data request for %s failed", currPair), ex);
216+
exceptionLogged.set(this.logRequestFailed("Ibit", currPair, start, ex));
215217
return Mono.empty();
216218
}).subscribeOn(this.mongoImportScheduler);
217219
Disposable subscribe = request.flatMap(myQuote -> this.itbitService.insertQuote(Mono.just(myQuote))
@@ -300,8 +302,7 @@ private void insertBfQuote(String currPair) {
300302
// log.info(res.toString());
301303
return result;
302304
}).timeout(Duration.ofSeconds(5L)).onErrorResume(ex -> {
303-
exceptionLogged.set(true);
304-
LOG.warn(String.format("Bitfinex data request for %s failed", currPair), ex);
305+
exceptionLogged.set(this.logRequestFailed("Bitfinex", currPair, start, ex));
305306
return Mono.empty();
306307
}).subscribeOn(this.mongoImportScheduler);
307308
Disposable subscribe = request.flatMap(myQuote -> this.bitfinexService.insertQuote(Mono.just(myQuote))

0 commit comments

Comments
 (0)