Skip to content

Commit

Permalink
Make existing work policy configurable in sync apis
Browse files Browse the repository at this point in the history
  • Loading branch information
MJ1998 committed Jan 13, 2025
1 parent 2a7e91f commit ffe746a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions engine/src/main/java/com/google/android/fhir/sync/Sync.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Google LLC
* Copyright 2023-2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,6 +67,7 @@ object Sync {
inline fun <reified W : FhirSyncWorker> oneTimeSync(
context: Context,
retryConfiguration: RetryConfiguration? = defaultRetryConfiguration,
existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.KEEP,
): Flow<CurrentSyncJobStatus> {
val uniqueWorkName = "${W::class.java.name}-oneTimeSync"
val flow = getWorkerInfo(context, uniqueWorkName)
Expand All @@ -75,7 +76,7 @@ object Sync {
WorkManager.getInstance(context)
.enqueueUniqueWork(
uniqueWorkName,
ExistingWorkPolicy.KEEP,
existingWorkPolicy,
oneTimeWorkRequest,
)
return combineSyncStateForOneTimeSync(context, uniqueWorkName, flow)
Expand All @@ -95,6 +96,7 @@ object Sync {
inline fun <reified W : FhirSyncWorker> periodicSync(
context: Context,
periodicSyncConfiguration: PeriodicSyncConfiguration,
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP,
): Flow<PeriodicSyncJobStatus> {
val uniqueWorkName = "${W::class.java.name}-periodicSync"
val flow = getWorkerInfo(context, uniqueWorkName)
Expand All @@ -103,7 +105,7 @@ object Sync {
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(
uniqueWorkName,
ExistingPeriodicWorkPolicy.KEEP,
existingPeriodicWorkPolicy,
periodicWorkRequest,
)
return combineSyncStateForPeriodicSync(context, uniqueWorkName, flow)
Expand Down

0 comments on commit ffe746a

Please sign in to comment.