Skip to content

Commit

Permalink
Fix eu-digital-green-certificates#191: Workers are not unique (eu-dig…
Browse files Browse the repository at this point in the history
…ital-green-certificates#207)

This makes sure we don't schedule a new worker every time we open the app. This should reduce the load in EU member national backends.
  • Loading branch information
denzilferreira authored Sep 14, 2021
1 parent 5a46e4d commit 94f87e5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ class DgcaApplication : Application(), Configuration.Provider {
}

WorkManager.getInstance(this).apply {
schedulePeriodicWorker<ConfigsLoadingWorker>()
schedulePeriodicWorker<RulesLoadWorker>()
schedulePeriodicWorker<LoadKeysWorker>()
schedulePeriodicWorker<CountriesLoadWorker>()
schedulePeriodicWorker<ValueSetsLoadWorker>()
schedulePeriodicWorker<ConfigsLoadingWorker>(WORKER_CONFIGS)
schedulePeriodicWorker<RulesLoadWorker>(WORKER_RULES)
schedulePeriodicWorker<LoadKeysWorker>(WORKER_KEYS)
schedulePeriodicWorker<CountriesLoadWorker>(WORKER_COUNTRIES)
schedulePeriodicWorker<ValueSetsLoadWorker>(WORKER_VALUESETS)
}

Timber.i("DGCA version ${BuildConfig.VERSION_NAME} is starting")
}

private inline fun <reified T : ListenableWorker> WorkManager.schedulePeriodicWorker() =
this.enqueue(
private inline fun <reified T : ListenableWorker> WorkManager.schedulePeriodicWorker(workerId: String) =
this.enqueueUniquePeriodicWork(workerId, ExistingPeriodicWorkPolicy.KEEP,
PeriodicWorkRequestBuilder<T>(1, TimeUnit.DAYS)
.setConstraints(
Constraints.Builder()
Expand All @@ -71,4 +71,12 @@ class DgcaApplication : Application(), Configuration.Provider {
)
.build()
)

companion object {
const val WORKER_CONFIGS = "workerConfigs"
const val WORKER_RULES = "workerRules"
const val WORKER_KEYS = "workerKeys"
const val WORKER_COUNTRIES = "workerCountries"
const val WORKER_VALUESETS = "workerValueSets"
}
}

0 comments on commit 94f87e5

Please sign in to comment.