From d4f9b4e29d2ad53c77334ab76b0ccda7f5858f9a Mon Sep 17 00:00:00 2001
From: Matthias Urhahn <matthias.urhahn@sap.com>
Date: Wed, 11 Nov 2020 16:55:43 +0100
Subject: [PATCH] Increase key retrieval worker launch interval to hourly
 (EXPOSUREAPP-3455) (#1574)

Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
---
 .../worker/BackgroundConstants.kt             | 12 ----------
 .../worker/BackgroundWorkBuilder.kt           |  6 ++---
 .../worker/BackgroundWorkHelper.kt            | 23 -------------------
 .../worker/BackgroundConstantsTest.kt         |  2 --
 .../worker/BackgroundWorkBuilderTest.kt       | 16 +++++++++++++
 .../worker/BackgroundWorkHelperTest.kt        | 12 ----------
 6 files changed, 18 insertions(+), 53 deletions(-)
 create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilderTest.kt

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundConstants.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundConstants.kt
index f15edf556..75b991b69 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundConstants.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundConstants.kt
@@ -64,18 +64,6 @@ object BackgroundConstants {
      */
     const val MINUTES_IN_DAY = 1440
 
-    /**
-     * Total tries count for diagnosis key retrieval per day
-     * Internal requirement
-     */
-    const val DIAGNOSIS_KEY_RETRIEVAL_TRIES_PER_DAY = 12
-
-    /**
-     * Maximum tries count for diagnosis key retrieval per day
-     * Google API limit
-     */
-    const val GOOGLE_API_MAX_CALLS_PER_DAY = 20
-
     /**
      * Total tries count for diagnosis key retrieval per day
      * Internal requirement
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilder.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilder.kt
index 4578ebaac..b109e8ba2 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilder.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilder.kt
@@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit
  * Set "kind delay" for accessibility reason.
  * Backoff criteria set to Linear type.
  *
- * @return PeriodicWorkRequest
+ * The launchInterval is 60 minutes as we want to check every hour, for new hour packages on the CDN.
  *
  * @see WorkTag.DIAGNOSIS_KEY_RETRIEVAL_PERIODIC_WORKER
  * @see BackgroundConstants.KIND_DELAY
@@ -19,9 +19,7 @@ import java.util.concurrent.TimeUnit
  * @see BackoffPolicy.LINEAR
  */
 fun buildDiagnosisKeyRetrievalPeriodicWork() =
-    PeriodicWorkRequestBuilder<DiagnosisKeyRetrievalPeriodicWorker>(
-        BackgroundWorkHelper.getDiagnosisKeyRetrievalPeriodicWorkTimeInterval(), TimeUnit.MINUTES
-    )
+    PeriodicWorkRequestBuilder<DiagnosisKeyRetrievalPeriodicWorker>(60, TimeUnit.MINUTES)
         .addTag(WorkTag.DIAGNOSIS_KEY_RETRIEVAL_PERIODIC_WORKER.tag)
         .setInitialDelay(
             BackgroundConstants.KIND_DELAY,
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt
index f72c11a86..2b8f2cebe 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt
@@ -16,17 +16,6 @@ import kotlin.random.Random
  */
 object BackgroundWorkHelper {
 
-    /**
-     * Calculate the time for diagnosis key retrieval periodic work
-     *
-     * @return Long
-     *
-     * @see BackgroundConstants.MINUTES_IN_DAY
-     * @see getDiagnosisKeyRetrievalMaximumCalls
-     */
-    fun getDiagnosisKeyRetrievalPeriodicWorkTimeInterval(): Long =
-        (BackgroundConstants.MINUTES_IN_DAY / getDiagnosisKeyRetrievalMaximumCalls()).toLong()
-
     /**
      * Calculate the time for diagnosis key retrieval periodic work
      *
@@ -38,18 +27,6 @@ object BackgroundWorkHelper {
         (BackgroundConstants.MINUTES_IN_DAY /
                 BackgroundConstants.DIAGNOSIS_TEST_RESULT_RETRIEVAL_TRIES_PER_DAY).toLong()
 
-    /**
-     * Get maximum calls count to Google API
-     *
-     * @return Long
-     *
-     * @see BackgroundConstants.DIAGNOSIS_KEY_RETRIEVAL_TRIES_PER_DAY
-     * @see BackgroundConstants.GOOGLE_API_MAX_CALLS_PER_DAY
-     */
-    fun getDiagnosisKeyRetrievalMaximumCalls() =
-        BackgroundConstants.DIAGNOSIS_KEY_RETRIEVAL_TRIES_PER_DAY
-            .coerceAtMost(BackgroundConstants.GOOGLE_API_MAX_CALLS_PER_DAY)
-
     /**
      * Get background noise one time work delay
      * The periodic job is already delayed by MIN_HOURS_TO_NEXT_BACKGROUND_NOISE_EXECUTION
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundConstantsTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundConstantsTest.kt
index 161df1e1a..a2247300d 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundConstantsTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundConstantsTest.kt
@@ -8,8 +8,6 @@ class BackgroundConstantsTest {
     @Test
     fun allBackgroundConstants() {
         Assert.assertEquals(BackgroundConstants.MINUTES_IN_DAY, 1440)
-        Assert.assertEquals(BackgroundConstants.DIAGNOSIS_KEY_RETRIEVAL_TRIES_PER_DAY, 12)
-        Assert.assertEquals(BackgroundConstants.GOOGLE_API_MAX_CALLS_PER_DAY, 20)
         Assert.assertEquals(BackgroundConstants.DIAGNOSIS_TEST_RESULT_RETRIEVAL_TRIES_PER_DAY, 12)
         Assert.assertEquals(BackgroundConstants.KIND_DELAY, 1L)
         Assert.assertEquals(BackgroundConstants.DIAGNOSIS_TEST_RESULT_PERIODIC_INITIAL_DELAY, 10L)
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilderTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilderTest.kt
new file mode 100644
index 000000000..f77fd6a7e
--- /dev/null
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkBuilderTest.kt
@@ -0,0 +1,16 @@
+package de.rki.coronawarnapp.worker
+
+import io.kotest.matchers.shouldBe
+import org.joda.time.Duration
+import org.junit.jupiter.api.Test
+import testhelpers.BaseTest
+
+class BackgroundWorkBuilderTest : BaseTest() {
+
+    @Test
+    fun `worker interval for key retrieval is 60 minutes, once every hour`() {
+        buildDiagnosisKeyRetrievalPeriodicWork().apply {
+            workSpec.intervalDuration shouldBe Duration.standardMinutes(60).millis
+        }
+    }
+}
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkHelperTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkHelperTest.kt
index eddc5f4c1..0ab0f5e23 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkHelperTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/worker/BackgroundWorkHelperTest.kt
@@ -5,13 +5,6 @@ import org.junit.Assert
 import org.junit.Test
 
 class BackgroundWorkHelperTest {
-    @Test
-    fun getDiagnosisKeyRetrievalPeriodicWorkTimeInterval() {
-        Assert.assertEquals(
-            BackgroundWorkHelper.getDiagnosisKeyRetrievalPeriodicWorkTimeInterval(),
-            120
-        )
-    }
 
     @Test
     fun getDiagnosisTestResultRetrievalPeriodicWorkTimeInterval() {
@@ -21,11 +14,6 @@ class BackgroundWorkHelperTest {
         )
     }
 
-    @Test
-    fun getDiagnosisKeyRetrievalMaximumCalls() {
-        Assert.assertEquals(BackgroundWorkHelper.getDiagnosisKeyRetrievalMaximumCalls(), 12)
-    }
-
     @Test
     fun getConstraintsForDiagnosisKeyOneTimeBackgroundWork() {
         val constraints = BackgroundWorkHelper.getConstraintsForDiagnosisKeyOneTimeBackgroundWork()
-- 
GitLab