rxjava 不触发时重试

问题描述

我正在使用 Web API 来检索一些报告。首先,我必须发送一个请求以获取一个 referenceCode,然后我使用该代码发出第二个请求以获取报告。问题是,当报告太大时,需要一些时间来准备,因此服务器返回警告/错误,指示我必须稍后检查。

因此,每当我收到来自前一个平面地图的警告或错误时,我都会尝试重复第二个请求,但它似乎不起作用。有什么想法吗?

/**
 * This method makes all the necessary tasks to import the operations from the XML report of IB.
 * It stores the new operations in IBRepository and returns the number of new operations to UI
 * using years MutableLiveData
 */
void checkForNewOperations()
{
    compositeDisposable.add(
            Task_RetrieveNewOperations.run()
                    .doOnNext(iIBNewTransactions -> IBRepository.getInstance().addTransactionsToNewOperationsList(iIBNewTransactions))
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(
                            iIBNewTransactions -> newOperations.setValue(Response.success(iIBNewTransactions.size())),error -> newOperations.setValue(Response.error(error))
                    ));
}

/**
 * This method is used to retrieve the new operations from IB Report
 * To get the report,two calls are needed. First one to get reference code and second one to get the XML report as string
 * Every node of the XML report is emitted one by one to convert it to the appropriate object (Trade or CashTransaction)
 * As there might be some splitted or duplicated operations,I group them in a single one
 * Then,we check is its transaction ID is already in Firebase to exclude it from the final returned list
 * @return The list of new operations from IB report
 */
public static Observable<List<iIB>> run()
{
    //First retrieve reference code from IB
    return IBRepository.getInstance().getReferenceCode()

            //Once reference code is retrieved,make second request to get XML report as string
            .flatMap((Function<String,ObservableSource<Document>>) referenceCode -> IBRepository.getInstance().getXMLReport(referenceCode))
            .flatMapSingle((Function<Document,Single<List<iIB>>>) xmlReport ->

            ...
}

public Observable<Document> getXMLReport(String referenceCode)
{
    final String STATUS = "Status";
    final String FAIL = "Fail";
    final String WARN = "Warn";
    final String ERROR_MESSAGE = "ErrorMessage";

    String url = IBConstants.DOWNLOAD_REPORT_URL + referenceCode + "&t=" + IBConstants.IB_TOKEN + "&v=3";
    return _Volley.getInstance().postRxVolley(url)
            .flatMap((Function<Result,ObservableSource<String>>) Response::processResultResponse)
            .flatMap((Function<String,ObservableSource<Document>>) xmlString -> Observable.fromCallable(() -> XMLParser.convertStringToXMLDocument(xmlString)))
            .flatMap(xmlDocument ->
            {
                String status = XMLParser.getSingleValueFromTag(xmlDocument,STATUS,0);

                return !status.contains(WARN) && !status.contains(FAIL) ?
                        Observable.just(xmlDocument) :
                        Observable.error(new Throwable(XMLParser.getSingleValueFromTag(xmlDocument,ERROR_MESSAGE,0)));
            })
            .retryWhen(throwables -> throwables.delay(1,TimeUnit.SECONDS));
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...