[2.13.0-arhc-opt] move monitoring to biz
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.mogo.commons.utils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.functions.Function;
|
||||
|
||||
public class RetryWithDelay implements Function<Observable<? extends Throwable>, Observable<?>> {
|
||||
|
||||
private final int maxRetries = 3;
|
||||
private final int retryDelayMillis = 5000;
|
||||
// 计数器
|
||||
private int retryCount = 0;
|
||||
|
||||
@Override
|
||||
public Observable<?> apply(Observable<? extends Throwable> observable) throws Exception {
|
||||
return observable.flatMap((Function<Throwable, ObservableSource<?>>) throwable -> {
|
||||
if (++retryCount <= maxRetries) {
|
||||
return Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
return Observable.error(throwable);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user