Skip to content

Commit ecf949a

Browse files
authored
Make existing work policy configurable in sync apis (#2765)
1 parent a21e824 commit ecf949a

File tree

1 file changed

+5
-3
lines changed
  • engine/src/main/java/com/google/android/fhir/sync

1 file changed

+5
-3
lines changed

engine/src/main/java/com/google/android/fhir/sync/Sync.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 Google LLC
2+
* Copyright 2023-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,6 +67,7 @@ object Sync {
6767
inline fun <reified W : FhirSyncWorker> oneTimeSync(
6868
context: Context,
6969
retryConfiguration: RetryConfiguration? = defaultRetryConfiguration,
70+
existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.KEEP,
7071
): Flow<CurrentSyncJobStatus> {
7172
val uniqueWorkName = "${W::class.java.name}-oneTimeSync"
7273
val flow = getWorkerInfo(context, uniqueWorkName)
@@ -75,7 +76,7 @@ object Sync {
7576
WorkManager.getInstance(context)
7677
.enqueueUniqueWork(
7778
uniqueWorkName,
78-
ExistingWorkPolicy.KEEP,
79+
existingWorkPolicy,
7980
oneTimeWorkRequest,
8081
)
8182
return combineSyncStateForOneTimeSync(context, uniqueWorkName, flow)
@@ -95,6 +96,7 @@ object Sync {
9596
inline fun <reified W : FhirSyncWorker> periodicSync(
9697
context: Context,
9798
periodicSyncConfiguration: PeriodicSyncConfiguration,
99+
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP,
98100
): Flow<PeriodicSyncJobStatus> {
99101
val uniqueWorkName = "${W::class.java.name}-periodicSync"
100102
val flow = getWorkerInfo(context, uniqueWorkName)
@@ -103,7 +105,7 @@ object Sync {
103105
WorkManager.getInstance(context)
104106
.enqueueUniquePeriodicWork(
105107
uniqueWorkName,
106-
ExistingPeriodicWorkPolicy.KEEP,
108+
existingPeriodicWorkPolicy,
107109
periodicWorkRequest,
108110
)
109111
return combineSyncStateForPeriodicSync(context, uniqueWorkName, flow)

0 commit comments

Comments
 (0)