mirror of
https://github.com/valitydev/adapter-bank-spring-boot-starter.git
synced 2024-11-06 01:05:20 +00:00
Merge pull request #14 from rbkmoney/ft/BJ-718/move-backoff-to-lib
Move backOff to lib
This commit is contained in:
commit
56d8dc81d6
5
pom.xml
5
pom.xml
@ -6,7 +6,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>adapter-bank-spring-boot-starter</artifactId>
|
||||
<version>0.0.10</version>
|
||||
<version>0.0.11</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -17,6 +17,7 @@
|
||||
<damsel.version>1.363-3074af1</damsel.version>
|
||||
<serializer.version>0.6.7</serializer.version>
|
||||
<hellgate-adapter-client.version>2.1.10</hellgate-adapter-client.version>
|
||||
<adapter-common-lib.version>0.0.14</adapter-common-lib.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -102,7 +103,7 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>adapter-common-lib</artifactId>
|
||||
<version>0.0.13</version>
|
||||
<version>${adapter-common-lib.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
|
@ -1,50 +0,0 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.backoff;
|
||||
|
||||
import com.rbkmoney.adapter.common.model.AdapterContext;
|
||||
import com.rbkmoney.adapter.common.state.backoff.BackOffExecution;
|
||||
import com.rbkmoney.adapter.common.state.backoff.ExponentialBackOff;
|
||||
import com.rbkmoney.adapter.common.state.backoff.TimeOptionsExtractors;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rbkmoney.adapter.common.state.backoff.ExponentialBackOff.*;
|
||||
|
||||
public class BackOffUtils {
|
||||
|
||||
public static BackOffExecution prepareBackOffExecution(
|
||||
AdapterContext adapterContext,
|
||||
Map<String, String> options) {
|
||||
return exponentialBackOff(adapterContext, options)
|
||||
.start();
|
||||
}
|
||||
|
||||
public static int prepareNextPollingInterval(
|
||||
AdapterContext adapterContext,
|
||||
Map<String, String> options) {
|
||||
return exponentialBackOff(adapterContext, options)
|
||||
.start()
|
||||
.nextBackOff()
|
||||
.intValue();
|
||||
}
|
||||
|
||||
private static ExponentialBackOff exponentialBackOff(
|
||||
AdapterContext adapterContext,
|
||||
Map<String, String> options) {
|
||||
final Long currentLocalTime = Instant.now().toEpochMilli();
|
||||
|
||||
Long startTime = adapterContext.getStartDateTimePolling() != null
|
||||
? adapterContext.getStartDateTimePolling().toEpochMilli()
|
||||
: currentLocalTime;
|
||||
Integer exponential = TimeOptionsExtractors.extractExponent(options, DEFAULT_EXPONENTIAL);
|
||||
Integer defaultInitialExponential = TimeOptionsExtractors.extractDefaultInitialExponential(options, DEFAULT_INITIAL_EXPONENTIAL);
|
||||
Integer maxTimeBackOff = TimeOptionsExtractors.extractMaxTimeBackOff(options, DEFAULT_MAX_TIME_BACK_OFF);
|
||||
|
||||
return new ExponentialBackOff(
|
||||
startTime,
|
||||
currentLocalTime,
|
||||
exponential,
|
||||
defaultInitialExponential,
|
||||
maxTimeBackOff);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user