-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mergedOptions + refactor * fine-tuning ExponentialBackOffPollingService * fix after review
- Loading branch information
Showing
21 changed files
with
264 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/dev/vality/disputes/polling/ExponentialBackOffPollingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.vality.disputes.polling; | ||
|
||
import dev.vality.adapter.flow.lib.model.PollingInfo; | ||
import dev.vality.adapter.flow.lib.utils.backoff.ExponentialBackOff; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
import static dev.vality.adapter.flow.lib.utils.backoff.ExponentialBackOff.*; | ||
|
||
public class ExponentialBackOffPollingService { | ||
|
||
public int prepareNextPollingInterval(PollingInfo pollingInfo, Map<String, String> options) { | ||
return exponentialBackOff(pollingInfo, options) | ||
.start() | ||
.nextBackOff() | ||
.intValue(); | ||
} | ||
|
||
private ExponentialBackOff exponentialBackOff(PollingInfo pollingInfo, Map<String, String> options) { | ||
final var currentLocalTime = Instant.now().toEpochMilli(); | ||
var startTime = pollingInfo.getStartDateTimePolling() != null | ||
? pollingInfo.getStartDateTimePolling().toEpochMilli() | ||
: currentLocalTime; | ||
var exponential = TimeOptionsExtractors.extractExponent(options, DEFAULT_MUTIPLIER); | ||
var defaultInitialExponential = | ||
TimeOptionsExtractors.extractDefaultInitialExponential(options, DEFAULT_INITIAL_INTERVAL_SEC); | ||
var maxTimeBackOff = TimeOptionsExtractors.extractMaxTimeBackOff(options, DEFAULT_MAX_INTERVAL_SEC); | ||
return new ExponentialBackOff( | ||
startTime, | ||
currentLocalTime, | ||
exponential, | ||
defaultInitialExponential, | ||
maxTimeBackOff); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/dev/vality/disputes/polling/TimeOptionsExtractors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.vality.disputes.polling; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class TimeOptionsExtractors { | ||
|
||
public static final String TIMER_EXPONENTIAL = "exponential"; | ||
public static final String MAX_TIME_BACKOFF_SEC = "max_time_backoff_sec"; | ||
public static final String DEFAULT_INITIAL_EXPONENTIAL_SEC = "default_initial_exponential_sec"; | ||
public static final String DISPUTE_TIMER_EXPONENTIAL = "dispute_exponential"; | ||
public static final String DISPUTE_MAX_TIME_BACKOFF_SEC = "dispute_max_time_backoff_sec"; | ||
public static final String DISPUTE_DEFAULT_INITIAL_EXPONENTIAL_SEC = "dispute_default_initial_exponential_sec"; | ||
|
||
public static Integer extractExponent(Map<String, String> options, int maxTimePolling) { | ||
return Integer.parseInt(options.getOrDefault( | ||
DISPUTE_TIMER_EXPONENTIAL, | ||
options.getOrDefault(TIMER_EXPONENTIAL, String.valueOf(maxTimePolling)))); | ||
} | ||
|
||
public static Integer extractMaxTimeBackOff(Map<String, String> options, int maxTimeBackOff) { | ||
return Integer.parseInt(options.getOrDefault( | ||
DISPUTE_MAX_TIME_BACKOFF_SEC, | ||
options.getOrDefault(MAX_TIME_BACKOFF_SEC, String.valueOf(maxTimeBackOff)))); | ||
} | ||
|
||
public static Integer extractDefaultInitialExponential(Map<String, String> options, int defaultInitialExponential) { | ||
return Integer.parseInt( | ||
options.getOrDefault(DISPUTE_DEFAULT_INITIAL_EXPONENTIAL_SEC, | ||
options.getOrDefault(DEFAULT_INITIAL_EXPONENTIAL_SEC, String.valueOf( | ||
defaultInitialExponential)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/dev/vality/disputes/schedule/model/ProviderData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.vality.disputes.schedule.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
public class ProviderData { | ||
|
||
private Map<String, String> options; | ||
private String defaultProviderUrl; | ||
|
||
} |
Oops, something went wrong.