Skip to content

Commit

Permalink
Fix first descriptor update on NewsMediaScan
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Nov 25, 2024
1 parent dac9752 commit db0a503
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AppWorkerManager(
suspend fun configureDescriptorAutoUpdate(): Boolean {
return withContext(backgroundDispatcher) {
val request = PeriodicWorkRequestBuilder<DescriptorUpdateWorker>(1, TimeUnit.DAYS)
.setInitialDelay(1, TimeUnit.DAYS) // avoid immediate start
.build()
workManager.enqueueUniquePeriodicWork(
DescriptorUpdateWorker.AutoUpdateWorkerName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import co.touchlab.kermit.Logger
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.serialization.encodeToString
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Running
Expand Down Expand Up @@ -41,19 +40,21 @@ class DescriptorUpdateWorker(
}

override suspend fun doWork(): Result {
return coroutineScope {
val descriptors = getDescriptors() ?: return@coroutineScope Result.failure()
if (descriptors.isEmpty()) return@coroutineScope Result.success(buildWorkData(descriptors.map { it.id }))
dependencies.getDescriptorUpdate.invoke(descriptors)
return@coroutineScope Result.success(buildWorkData(descriptors.map { it.id }))
val descriptors = getDescriptors() ?: return Result.failure()
if (descriptors.isEmpty()) {
Logger.i("Skipping DescriptorUpdateWorker: no descriptors to update")
return Result.success(buildWorkData(descriptors.map { it.id }))
}
dependencies.getDescriptorUpdate.invoke(descriptors)
return Result.success(buildWorkData(descriptors.map { it.id }))
}

private suspend fun getDescriptors(): List<InstalledTestDescriptorModel>? {
val descriptorsJson = inputData.getString(DATA_KEY_DESCRIPTORS)
if (descriptorsJson != null) {
try {
val ids = json.decodeFromString<List<InstalledTestDescriptorModel.Id>>(descriptorsJson)
val ids =
json.decodeFromString<List<InstalledTestDescriptorModel.Id>>(descriptorsJson)
return testDescriptorRepository.selectByRunIds(ids).first()
} catch (e: Exception) {
Logger.w("Could not start update worker: invalid configuration", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ interface OrganizationConfigInterface {
val baseSoftwareName: String

val ooniApiBaseUrl: String
get() = "https://api.ooni.org"
get() = "https://api.dev.ooni.io"

val ooniRunDomain: String
get() = "run.ooni.org"
get() = "run.test.ooni.org"

val ooniRunDashboardUrl: String
get() = "https://run.ooni.org"
get() = "https://run.test.ooni.org"

val explorerUrl: String
get() = "https://explorer.test.ooni.org"
Expand Down
6 changes: 2 additions & 4 deletions composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,15 @@ fun App(
LaunchedEffect(Unit) {
dependencies.bootstrapTestDescriptors()
dependencies.bootstrapPreferences()
dependencies.configureDescriptorAutoUpdate()
dependencies.fetchDescriptorUpdate(null)
}
LaunchedEffect(Unit) {
dependencies.finishInProgressData()
}
LaunchedEffect(Unit) {
dependencies.observeAndConfigureAutoRun()
}
LaunchedEffect(Unit) {
dependencies.configureDescriptorAutoUpdate()
dependencies.fetchDescriptorUpdate(null)
}

LaunchedEffect(deepLink) {
when (deepLink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fun webConnectivityPreferences(
return emptyList()
}

fun preferenceDefaults(): List<Pair<SettingsKey,Any>> {
fun preferenceDefaults(): List<Pair<SettingsKey, Any>> {
return emptyList()
}

0 comments on commit db0a503

Please sign in to comment.