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

Fix Sync Status: Harmonize FHIR and Custom Sync Completion for 'Sync Complete' #3650

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceDataSource
import org.smartregister.fhircore.engine.di.NetworkModule
import org.smartregister.fhircore.engine.domain.model.MultiSelectViewAction
import org.smartregister.fhircore.engine.sync.CustomSyncState
import org.smartregister.fhircore.engine.sync.CustomWorkerState
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.KnowledgeManagerUtil
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
Expand Down Expand Up @@ -526,30 +528,48 @@
suspend fun fetchResources(
gatewayModeHeaderValue: String? = null,
url: String,
enableCustomSyncWorkerLogs: Boolean = false,
) {
val resultBundle =
runCatching {
if (gatewayModeHeaderValue.isNullOrEmpty()) {
fhirResourceDataSource.getResource(url)
} else {
fhirResourceDataSource.getResourceWithGatewayModeHeader(gatewayModeHeaderValue, url)
}
runCatching {
if (enableCustomSyncWorkerLogs) {
Timber.d("Posting state: InProgress")
CustomWorkerState.postState(CustomSyncState.InProgress)

Check warning on line 536 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt#L535-L536

Added lines #L535 - L536 were not covered by tests
}
.onFailure { throwable ->
Timber.e("Error occurred while retrieving resource via URL $url", throwable)

Timber.d("Fetching page with URL: $url")
if (gatewayModeHeaderValue.isNullOrEmpty()) {
fhirResourceDataSource.getResource(url)
} else {
fhirResourceDataSource.getResourceWithGatewayModeHeader(gatewayModeHeaderValue, url)
}
.getOrThrow()
}
.onFailure { throwable ->
Timber.e("Error occurred while retrieving resource via URL $url", throwable)

Check warning on line 547 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt#L547

Added line #L547 was not covered by tests
if (enableCustomSyncWorkerLogs) {
Timber.d("Posting state: Failed")
CustomWorkerState.postState(CustomSyncState.Failed(throwable.localizedMessage))

Check warning on line 550 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt#L549-L550

Added lines #L549 - L550 were not covered by tests
}
return // Exit on failure
}
.onSuccess { resultBundle ->
val nextPageUrl = resultBundle.getLink(PAGINATION_NEXT)?.url

val nextPageUrl = resultBundle.getLink(PAGINATION_NEXT)?.url
processResultBundleEntries(resultBundle.entry)

processResultBundleEntries(resultBundle.entry)

if (!nextPageUrl.isNullOrEmpty()) {
fetchResources(
gatewayModeHeaderValue = gatewayModeHeaderValue,
url = nextPageUrl,
)
}
if (!nextPageUrl.isNullOrEmpty()) {
fetchResources(
gatewayModeHeaderValue = gatewayModeHeaderValue,
url = nextPageUrl,
enableCustomSyncWorkerLogs = enableCustomSyncWorkerLogs,
)
} else {
Timber.d("No more pages to fetch. Fetching completed.")
if (enableCustomSyncWorkerLogs) {
Timber.d("Posting state: Success")
CustomWorkerState.postState(CustomSyncState.Success)

Check warning on line 569 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt#L568-L569

Added lines #L568 - L569 were not covered by tests
}
}
}
}

private suspend fun processResultBundleEntries(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

sealed class CustomSyncState {
object InProgress : CustomSyncState()

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomSyncState.kt#L20

Added line #L20 was not covered by tests

object Success : CustomSyncState()

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomSyncState.kt#L22

Added line #L22 was not covered by tests

data class Failed(val error: String? = null) : CustomSyncState()

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomSyncState.kt#L24

Added line #L24 was not covered by tests

object Idle : CustomSyncState()

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomSyncState.kt#L26

Added line #L26 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
fetchResources(
gatewayModeHeaderValue = ConfigurationRegistry.FHIR_GATEWAY_MODE_HEADER_VALUE,
url = url,
enableCustomSyncWorkerLogs = true,

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomSyncWorker.kt#L59

Added line #L59 was not covered by tests
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

object CustomWorkerState {
private val _workerState = MutableStateFlow<CustomSyncState>(CustomSyncState.Idle)
val workerState: StateFlow<CustomSyncState> = _workerState

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomWorkerState.kt#L23-L24

Added lines #L23 - L24 were not covered by tests

fun postState(state: CustomSyncState) {
_workerState.value = state

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

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/sync/CustomWorkerState.kt#L27

Added line #L27 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.work.BackoffPolicy
import androidx.work.Constraints
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.BackoffCriteria
import com.google.android.fhir.sync.CurrentSyncJobStatus
import com.google.android.fhir.sync.LastSyncJobStatus
import com.google.android.fhir.sync.PeriodicSyncConfiguration
import com.google.android.fhir.sync.PeriodicSyncJobStatus
import com.google.android.fhir.sync.RepeatInterval
import com.google.android.fhir.sync.RetryConfiguration
import com.google.android.fhir.sync.Sync
import com.google.android.fhir.sync.SyncJobStatus
import com.google.android.fhir.sync.download.ResourceParamsBasedDownloadWorkManager
Expand Down Expand Up @@ -80,11 +77,6 @@
.setConstraints(
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(),
)
.setBackoffCriteria(
BackoffPolicy.LINEAR,
10,
TimeUnit.SECONDS,
)
.build(),
)
}
Expand All @@ -103,16 +95,6 @@
syncConstraints =
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(),
repeat = RepeatInterval(interval = interval, timeUnit = TimeUnit.MINUTES),
retryConfiguration =
RetryConfiguration(
backoffCriteria =
BackoffCriteria(
backoffDelay = 10,
timeUnit = TimeUnit.SECONDS,
backoffPolicy = BackoffPolicy.EXPONENTIAL,
),
maxRetries = 3,
),
),
)
.handlePeriodicSyncJobStatus(this)
Expand All @@ -121,14 +103,34 @@
private fun Flow<PeriodicSyncJobStatus>.handlePeriodicSyncJobStatus(
coroutineScope: CoroutineScope,
) {
this.onEach {
this.onEach { status ->
syncListenerManager.onSyncListeners.forEach { onSyncListener ->
onSyncListener.onSync(
if (it.lastSyncJobStatus as? LastSyncJobStatus.Succeeded != null) {
CurrentSyncJobStatus.Succeeded((it.lastSyncJobStatus as LastSyncJobStatus).timestamp)
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

// Check if lastSyncJobStatus is not null and is of type Succeeded
val syncStatus =

Check warning on line 111 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

Added line #L111 was not covered by tests
if (status.lastSyncJobStatus as? LastSyncJobStatus.Succeeded != null) {
CurrentSyncJobStatus.Succeeded(
(status.lastSyncJobStatus as LastSyncJobStatus.Succeeded).timestamp,

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#L113-L114

Added lines #L113 - L114 were not covered by tests
)
} else {
it.currentSyncJobStatus
},
status.currentSyncJobStatus

Check warning on line 117 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#L117

Added line #L117 was not covered by tests
}

onSyncListener.onSync(syncStatus)

Check warning on line 120 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#L120

Added line #L120 was not covered by tests
}

if (
status.currentSyncJobStatus is CurrentSyncJobStatus.Succeeded ||
status.lastSyncJobStatus is LastSyncJobStatus.Succeeded
) {
Timber.d("Periodic sync succeeded. Triggering CustomSyncWorker...")
workManager.enqueue(
OneTimeWorkRequestBuilder<CustomSyncWorker>()
.setConstraints(
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(),

Check warning on line 131 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#L127-L131

Added lines #L127 - L131 were not covered by tests
)
.build(),

Check warning on line 133 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#L133

Added line #L133 was not covered by tests
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.domain.model.Language
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.sync.CustomSyncState
import org.smartregister.fhircore.quest.integration.Faker
import org.smartregister.fhircore.quest.ui.main.appMainUiStateOf
import org.smartregister.fhircore.quest.ui.register.FAB_BUTTON_REGISTER_TEST_TAG
Expand Down Expand Up @@ -610,6 +611,7 @@ class RegisterScreenTest {
currentSyncJobStatus = CurrentSyncJobStatus.Succeeded(OffsetDateTime.now()),
),
onAppMainEvent = {},
customSyncState = CustomSyncState.Success,
searchQuery = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.compose.material.Scaffold
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
Expand Down Expand Up @@ -119,6 +120,7 @@
val scaffoldState = rememberScaffoldState()
val uiState: AppMainUiState = appMainViewModel.appMainUiState.value
val appDrawerUIState = appMainViewModel.appDrawerUiState.value
val customSyncState = appMainViewModel.customSyncState.collectAsState().value

Check warning on line 123 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L123

Added line #L123 was not covered by tests
val openDrawer: (Boolean) -> Unit = { open: Boolean ->
coroutineScope.launch {
if (open) scaffoldState.drawerState.open() else scaffoldState.drawerState.close()
Expand Down Expand Up @@ -192,6 +194,7 @@
appDrawerUIState = appDrawerUIState,
clearMapLiveData = geoWidgetLauncherViewModel.clearMapLiveData,
geoJsonFeatures = geoWidgetLauncherViewModel.geoJsonFeatures,
customSyncState = customSyncState,

Check warning on line 197 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L197

Added line #L197 was not covered by tests
launchQuestionnaire = geoWidgetLauncherViewModel::launchQuestionnaire,
decodeImage = geoWidgetLauncherViewModel::getImageBitmap,
onAppMainEvent = appMainViewModel::onEvent,
Expand Down Expand Up @@ -223,12 +226,11 @@
)
}
}
is CurrentSyncJobStatus.Succeeded,
is CurrentSyncJobStatus.Failed, -> {
is CurrentSyncJobStatus.Succeeded -> {
appMainViewModel.updateAppDrawerUIState(currentSyncJobStatus = syncJobStatus)

Check warning on line 230 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L230

Added line #L230 was not covered by tests
}
is CurrentSyncJobStatus.Failed -> {
appMainViewModel.updateAppDrawerUIState(currentSyncJobStatus = syncJobStatus)
if (syncJobStatus is CurrentSyncJobStatus.Succeeded) {
geoWidgetLauncherViewModel.onEvent(GeoWidgetEvent.ClearMap)
}
geoWidgetLauncherViewModel.onEvent(
GeoWidgetEvent.RetrieveFeatures(
geoWidgetConfig = geoWidgetConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.smartregister.fhircore.engine.configuration.geowidget.GeoWidgetConfiguration
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.domain.model.ToolBarHomeNavigation
import org.smartregister.fhircore.engine.sync.CustomSyncState
import org.smartregister.fhircore.engine.ui.components.register.LoaderDialog
import org.smartregister.fhircore.engine.util.extension.showToast
import org.smartregister.fhircore.geowidget.model.GeoJsonFeature
Expand Down Expand Up @@ -71,6 +72,7 @@
appDrawerUIState: AppDrawerUIState,
clearMapLiveData: MutableLiveData<Boolean>,
geoJsonFeatures: MutableLiveData<List<GeoJsonFeature>>,
customSyncState: CustomSyncState = CustomSyncState.Idle,
launchQuestionnaire: (QuestionnaireConfig, GeoJsonFeature, Context) -> Unit,
decodeImage: ((String) -> Bitmap?)?,
onAppMainEvent: (AppMainEvent) -> Unit,
Expand Down Expand Up @@ -126,6 +128,7 @@
appDrawerUIState = appDrawerUIState,
onAppMainEvent = onAppMainEvent,
openDrawer = openDrawer,
customSyncState = customSyncState,

Check warning on line 131 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherScreen.kt#L131

Added line #L131 was not covered by tests
)
},
) { innerPadding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import javax.inject.Inject
import kotlin.time.Duration
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.hl7.fhir.r4.model.QuestionnaireResponse
Expand All @@ -59,7 +62,8 @@
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.CustomSyncState
import org.smartregister.fhircore.engine.sync.CustomWorkerState
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 @@ -89,6 +93,7 @@
import org.smartregister.fhircore.quest.ui.shared.models.QuestionnaireSubmission
import org.smartregister.fhircore.quest.util.extensions.handleClickEvent
import org.smartregister.fhircore.quest.util.extensions.schedulePeriodically
import timber.log.Timber

@HiltViewModel
class AppMainViewModel
Expand Down Expand Up @@ -134,6 +139,35 @@
configurationRegistry.retrieveConfigurations(ConfigType.MeasureReport)
}

private val _customSyncState = MutableStateFlow<CustomSyncState>(CustomSyncState.Idle)
val customSyncState: StateFlow<CustomSyncState> = _customSyncState.asStateFlow()

Check warning on line 143 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L142-L143

Added lines #L142 - L143 were not covered by tests

init {
observeWorkerSyncState()

Check warning on line 146 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L145-L146

Added lines #L145 - L146 were not covered by tests
}

private fun observeWorkerSyncState() {
viewModelScope.launch {

Check warning on line 150 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L150

Added line #L150 was not covered by tests
CustomWorkerState.workerState.collect { syncState ->
when (syncState) {
CustomSyncState.InProgress -> {
Timber.d("Custom Sync Worker InProgress")
_customSyncState.value = CustomSyncState.InProgress

Check warning on line 155 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L154-L155

Added lines #L154 - L155 were not covered by tests
}
CustomSyncState.Failed() -> {
Timber.d("Custom Sync Worker Failed")
_customSyncState.value = CustomSyncState.Failed("")

Check warning on line 159 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L158-L159

Added lines #L158 - L159 were not covered by tests
}
CustomSyncState.Success -> {
_customSyncState.value = CustomSyncState.Success
Timber.d("Custom Sync Worker Finished")

Check warning on line 163 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt#L162-L163

Added lines #L162 - L163 were not covered by tests
}
else -> {}
}
}
}
}

fun retrieveAppMainUiState(refreshAll: Boolean = true) {
if (refreshAll) {
appMainUiState.value =
Expand Down Expand Up @@ -468,12 +502,6 @@
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
Loading