FileDownloader icon indicating copy to clipboard operation
FileDownloader copied to clipboard

Time between retries

Open ruifcardoso opened this issue 10 years ago • 3 comments

Hi, I would like to know if it is possible to add a timeout interval between retries? This is because I'm testing this feature and my current issue is that, if the user loses connection for longer than the default timeout, all the retries will be executed one after the other, without having any margin between them, even if there is no connection.

Is it possible to add this?

Thanks

ruifcardoso avatar May 04 '16 17:05 ruifcardoso

Yep, you can customize the connection timeout or others for the OkhttpClient which used for FileDownload Engine.(Ref: https://github.com/lingochamp/FileDownloader/blob/master/demo/src/main/java/com/liulishuo/filedownloader/demo/DemoApplication.java#L42)

Jacksgong avatar May 05 '16 00:05 Jacksgong

I think that the problem is that I tested it be closing all internet connections (mobile data and wi-fi). When I do it, the retries don't wait the timeout.

Here is the example:

05-05 05:01:22.154 23347-23347/com.myapp.pt I/FileDownloaderListener: Download retry. Retries: 1 Max retries: 5
05-05 05:01:22.165 23347-23347/com.myapp.pt I/FileDownloaderListener: Download retry. Retries: 3 Max retries: 5
05-05 05:01:22.165 23347-23347/com.myapp.pt I/FileDownloaderListener: Download retry. Retries: 3 Max retries: 5
05-05 05:01:22.173 23347-23347/com.myapp.pt I/FileDownloaderListener: Download retry. Retries: 5 Max retries: 5
05-05 05:01:22.173 23347-23347/com.myapp.pt I/FileDownloaderListener: Download retry. Retries: 5 Max retries: 5
05-05 05:01:22.174 23347-23347/com.myapp.pt I/FileDownloaderListener: Download error. Retries: 5 Message: Unable to resolve host "****.com": No address associated with hostname

Here is my init code:

FileDownloader.init(getApplicationContext(),
                new FileDownloadHelper.OkHttpClientCustomMaker() { // is not has to provide.
                    @Override
                    public OkHttpClient customMake() {
                        // just for OkHttpClient customize.
                        final OkHttpClient.Builder builder = new OkHttpClient.Builder();
                        // you can set the connection timeout.
                        builder.connectTimeout(15000, TimeUnit.MILLISECONDS);
                        // you can set the HTTP proxy.
                        builder.proxy(Proxy.NO_PROXY);
                        // etc.
                        return builder.build();
                    }
                });

ruifcardoso avatar May 05 '16 09:05 ruifcardoso

Yes, If there isn't any internet connection, okHttp would throw an exception immediately.

Jacksgong avatar May 05 '16 15:05 Jacksgong