Skip to content

Commit

Permalink
Merge pull request #307 from ooni/fix-first-update-nms
Browse files Browse the repository at this point in the history
Fix first descriptor update on NewsMediaScan
  • Loading branch information
sdsantos authored Nov 26, 2024
2 parents b25876e + 315ea66 commit cea04cb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 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 @@ -44,7 +44,10 @@ class DescriptorUpdateWorker(
override suspend fun doWork(): Result {
try {
val descriptors = getDescriptors() ?: return Result.failure()
if (descriptors.isEmpty()) return Result.success(buildWorkData(descriptors.map { it.id }))
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 }))
} catch (e: CancellationException) {
Expand All @@ -57,7 +60,8 @@ class DescriptorUpdateWorker(
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: SerializationException) {
Logger.w("Could not start update worker: invalid configuration", e)
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 cea04cb

Please sign in to comment.