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
448 stars 34 forks source link

EMERGENCY, State and Response retrying* #24

Closed Wizardeirr closed 1 month ago

Wizardeirr commented 2 months 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 2 months ago

Could you share the code snippet?

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

Wizardeirr commented 2 months 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 2 months 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 2 months ago

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

khushpanchal commented 2 months 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 2 months 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}"
                        )
                    }
                }
            }

        }
    }
}

}

khushpanchal commented 1 month ago

@Wizardeirr I am not able to reproduce this, it is working fine on my device, pls check the complete code, seems like your scope is cancelling somehow. Please debug and let me know what is causing the issue, seems like it is not related to library.

Closing this for now. Will reopen if required