[2.13.0-arhc-opt] move monitoring to biz

This commit is contained in:
zhongchao
2023-01-04 21:03:30 +08:00
parent 2b679720bc
commit 19d02aa429
55 changed files with 77 additions and 1032 deletions

View File

@@ -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);
});
}
}