Fetch: REQUEST_WITH_ID_ALREADY_EXIST

Created on 4 May 2018  路  1Comment  路  Source: tonyofrancis/Fetch

I have something Like this.

...
fileFetcher = new Fetch.Builder(this, "Main").enableLogging(true).setDownloadConcurrentLimit(4).build();
...
public Request createRequest(url,name){
        Request request = new Request(url, name);
        request.setPriority(Priority.NORMAL);
        request.setGroupId(10001);
        request.setNetworkType(NetworkType.WIFI_ONLY);
        return request;
}
...
fileFetcher.enqueue(requests, new Func<List<? extends Download>>() {
            @Override
            public void call(List<? extends Download> downloads) {
                Log.v("FILEDOWNLOAD", "ENQUED SUCCESSFULLY");
            }
        }, new Func<Error>() {
            @Override
            public void call(Error error) {
                Log.e("FILEDOWNLOAD", "Error While Enqueing Requests");
                Log.e("FILEDOWNLOAD", error.toString());
            }
        });
...
//I am Getting the Following Error when I En-queue them via the list. Or Even when I do them Separately. Why?
E/FILEDOWNLOAD: Error While Enqueing Requests
    REQUEST_WITH_ID_ALREADY_EXIST

help wanted

Most helpful comment

@LaserStony Fetch stores all request in a database(This is used to manage downloads). If the database already has a request with the same id request.getId() or a request with the same url request.getUrl(), Fetch will reject the new request and you will get an error. As of version 2.0.0-RC19, you can tell Fetch to replace an existing request without you having to manually remove them with Fetch.remove(request.getId()).

Solution: Add the RequestOptions.RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE or RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH on the Fetch Builder. These options first removes any requests in the database that matches the enqueuing request's id or file. FRESH will force a download from the beginning. See the Java Docs for RequestOptions.

Example:

 final Fetch fetch = new Fetch.Builder(this, "namespace")
                .setLogger(new FetchTimberLogger())
                .setDownloader(new OkHttpDownloader())
                .setDownloadConcurrentLimit(4)
                .enableLogging(true)
                .enableRetryOnNetworkGain(true)
                .addRequestOptions(RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH)
                .build();

>All comments

@LaserStony Fetch stores all request in a database(This is used to manage downloads). If the database already has a request with the same id request.getId() or a request with the same url request.getUrl(), Fetch will reject the new request and you will get an error. As of version 2.0.0-RC19, you can tell Fetch to replace an existing request without you having to manually remove them with Fetch.remove(request.getId()).

Solution: Add the RequestOptions.RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE or RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH on the Fetch Builder. These options first removes any requests in the database that matches the enqueuing request's id or file. FRESH will force a download from the beginning. See the Java Docs for RequestOptions.

Example:

 final Fetch fetch = new Fetch.Builder(this, "namespace")
                .setLogger(new FetchTimberLogger())
                .setDownloader(new OkHttpDownloader())
                .setDownloadConcurrentLimit(4)
                .enableLogging(true)
                .enableRetryOnNetworkGain(true)
                .addRequestOptions(RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH)
                .build();

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MohammadFneish7 picture MohammadFneish7  路  4Comments

Mahan3340 picture Mahan3340  路  4Comments

burhanaksendir picture burhanaksendir  路  4Comments

DeevD picture DeevD  路  3Comments

cepero91 picture cepero91  路  4Comments