khushpanchal / Ketch

An Android File downloader library based on WorkManager with pause and resume support.
https://medium.com/@khush.panchal123/ketch-android-file-downloader-library-7369f7b93bd1
395 stars 26 forks source link

EMERGENCY, State and Response retrying* #24

Open Wizardeirr opened 3 weeks ago

Wizardeirr commented 3 weeks ago

My APKs is downloading but state is stucked on QUEUED. ITS blocking all my other SYNTAX. Because i am trying install when APK download is SUCCESS. Second problem is Response. Thats entry 3 times SUCCESS. thats mean my codes catching 3 times to SUCCESS and all codes blow up

khushpanchal commented 3 weeks ago

Could you share the code snippet?

For second problem, how are you observing? Also which version you are using?

Wizardeirr commented 3 weeks ago

ketch.download(url,path,fileName,tag, meta), ketchHelper.observeDownload(id) { downloadModel ->

                            LogService.v(
                                "DownloadLibrary",
                                "${downloadModel.id} - ${downloadModel.fileName} - ${downloadModel.status} - ${downloadModel.progress} - ${downloadModel.failureReason}"
                            )

                        }

2.0.1

khushpanchal commented 3 weeks ago

For first part, if it is stucked in onqueued, it means WorkManager doesn't start the work, have you tried debug it? I need to check and reproduce when this can happen, please give me some time to get back. Additionally could you try some mechanism where if it does not start for sometime, you cancel the download and retry it?

For second part, as we are observing the flow, every time there is a call to observeDownloadById, it will give last state. To handle something only once when download is success, consider adding a flag and turn it off once success is called.

Wizardeirr commented 3 weeks ago

okay in addition files downloading but state already same. not change but files had been downloaded

khushpanchal commented 3 weeks ago

In which scope you are calling observeDownload?, Could you check if due to some reason whether your scope is not cancelling?

Pls provide code snippet, it will help me reproduce?

Wizardeirr commented 3 weeks ago

CoroutineScope(Dispatchers.IO).launch { files.forEach { fileModel ->

    url?.let {
        var urlString = url + "/api/v1/appcat/download/${fileModel.FileUUID}"
        if (fileModel.FileName != null && fileModel.FileUUID != null) {

            var id = ketchHelper.download(
                urlString,
                fileModel.FileName,
                path,
                "policy",
                fileModel.PackageName!!
            )

            if (id != 0){
                ketchHelper.observeDownload(id) { downloadModel ->
                    LogService.v(
                        "DownloadLibrary",
                        "${downloadModel.id} - ${downloadModel.fileName} - ${downloadModel.status} - ${downloadModel.progress}"
                    )
                    if (downloadModel.status == Status.SUCCESS) {
                        LogService.v(
                            "DownloadLibrary",
                            "${downloadModel.id} - ${downloadModel.fileName} - ${downloadModel.status} - ${downloadModel.progress}"
                        )

                    } else if (downloadModel.status == Status.FAILED) {
                        LogService.v(
                            "DownloadLibrary",
                            "${downloadModel.id} - ${downloadModel.fileName} - ${downloadModel.status} - ${downloadModel.failureReason}"
                        )
                    }
                }
            }

        }
    }
}

}