Hi Tony.
I'm iterating through a list of URLs and for each item I'm calling fun enqueue(request: Request): Convertible
This is my configuration settings.
val client = OkHttpClient.Builder()
.callTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
.connectTimeout(5, TimeUnit.SECONDS)
.followRedirects(true)
.followSslRedirects(true)
.build()
val downloader = OkHttpDownloader(client, Downloader.FileDownloaderType.SEQUENTIAL)
val fetchConfiguration: FetchConfiguration = FetchConfiguration.Builder(context)
.setNotificationManager(null)
.setNamespace("my.namespace")
.setProgressReportingInterval(1000)
.setDownloadConcurrentLimit(1)
.setHttpDownloader(downloader)
.build()
fetch = RxFetch.getRxInstance(fetchConfiguration)
@gbirk hasActiveDownloads only returns if a download is activity downloading. The name of the method is miss leading and has to be updated. I will be working on this to include queued downloads as well. Not sure when I will have a fix but will post back soon.
Useful if you add something like hasAnyActiveOrUpcomingDownloads()
Most of the time we check this for shutdown the service.
@gbirk @jpvs0101 Fetch 2.3.4 has be released. hasActiveDownloads has been updated to correctly return true when there are downloads with a downloading or queued status. Note: this method cannot be called on a ui thread.
Also add new awaitFinish() and awaitFinishTimeout() methods that block a background thread until Fetch completes all queued downloads. No need to create your own loops to check. Note: this method cannot be called on a ui thread or else an exception is thrown.
Hi Tony. Quick question, do we have an option to call for an Observable or Flowable on this?
Sorry I'm a bit late on this, but I saw that FetchHandlerImpl throws an exception if the call is done on the main thread.
override fun hasActiveDownloads(): Boolean {
if (Thread.currentThread() == Looper.getMainLooper().thread) {
throw FetchException(BLOCKING_CALL_ON_UI_THREAD)
}
return databaseManager.getPendingCount() > 0
}
but RxFetchImpl catches the exception and returns false.
override val hasActiveDownloads: Boolean
get() {
return try {
fetchHandler.hasActiveDownloads()
} catch (e: Exception) {
false
}
}
I think this might create some confusion with hasActiveDownloads returning false because the contract is not being followed correctly. Maybe just propagate the exception?
Most helpful comment
@gbirk @jpvs0101 Fetch 2.3.4 has be released. hasActiveDownloads has been updated to correctly return true when there are downloads with a downloading or queued status. Note: this method cannot be called on a ui thread.
Also add new awaitFinish() and awaitFinishTimeout() methods that block a background thread until Fetch completes all queued downloads. No need to create your own loops to check. Note: this method cannot be called on a ui thread or else an exception is thrown.