Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain periodic sync completion with CustomSyncWorker #3635

Closed
wants to merge 12 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,26 @@
private fun Flow<PeriodicSyncJobStatus>.handlePeriodicSyncJobStatus(
coroutineScope: CoroutineScope,
) {
this.onEach {
this.onEach { status ->
syncListenerManager.onSyncListeners.forEach { onSyncListener ->
Timber.d("fhir sync worker...")

Check warning on line 108 in android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt#L108

Added line #L108 was not covered by tests
onSyncListener.onSync(
if (it.lastSyncJobStatus != null) {
CurrentSyncJobStatus.Succeeded((it.lastSyncJobStatus as LastSyncJobStatus).timestamp)
} else it.currentSyncJobStatus,
if (status.lastSyncJobStatus != null) {
Lentumunai-Mark marked this conversation as resolved.
Show resolved Hide resolved
Lentumunai-Mark marked this conversation as resolved.
Show resolved Hide resolved
CurrentSyncJobStatus.Succeeded(
(status.lastSyncJobStatus as LastSyncJobStatus).timestamp,

Check warning on line 112 in android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt#L111-L112

Added lines #L111 - L112 were not covered by tests
)
} else status.currentSyncJobStatus,

Check warning on line 114 in android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt#L114

Added line #L114 was not covered by tests
)
}

if (status.currentSyncJobStatus is CurrentSyncJobStatus.Succeeded) {
Lentumunai-Mark marked this conversation as resolved.
Show resolved Hide resolved
Timber.d("Periodic sync succeeded. Triggering CustomSyncWorker...")
workManager.enqueue(
OneTimeWorkRequestBuilder<CustomSyncWorker>()
.setConstraints(
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(),

Check warning on line 123 in android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt#L119-L123

Added lines #L119 - L123 were not covered by tests
)
.build(),

Check warning on line 125 in android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/SyncBroadcaster.kt#L125

Added line #L125 was not covered by tests
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import org.smartregister.fhircore.engine.domain.model.LauncherType
import org.smartregister.fhircore.engine.domain.model.MultiSelectViewAction
import org.smartregister.fhircore.engine.sync.CustomSyncWorker
import org.smartregister.fhircore.engine.sync.SyncBroadcaster
import org.smartregister.fhircore.engine.task.FhirCarePlanGenerator
import org.smartregister.fhircore.engine.task.FhirCompleteCarePlanWorker
Expand Down Expand Up @@ -448,12 +447,6 @@ constructor(
initialDelay = INITIAL_DELAY,
)

schedulePeriodically<CustomSyncWorker>(
workId = CustomSyncWorker.WORK_ID,
repeatInterval = applicationConfiguration.syncInterval,
initialDelay = 0,
)

measureReportConfigurations.forEach { measureReportConfig ->
measureReportConfig.scheduledGenerationDuration?.let { scheduledGenerationDuration ->
schedulePeriodically<MeasureReportMonthPeriodWorker>(
Expand Down
Loading