From 6ebec7935d1a388f0a5ce1b86cab6408ce8ff8f8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 16 Aug 2023 13:54:23 +0200 Subject: [PATCH] improve calculation workflow behavior --- .../androidaps/workflow/CalculationWorkflowImpl.kt | 8 ++++---- .../info/nightscout/workflow/PrepareBasalDataWorker.kt | 1 + .../workflow/PrepareIobAutosensGraphDataWorker.kt | 1 + .../workflow/PrepareTemporaryTargetDataWorker.kt | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt index 475e4e5f9b..6d1a364a53 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflowImpl.kt @@ -198,23 +198,23 @@ class CalculationWorkflowImpl @Inject constructor( .build() ) .then( - job == MAIN_CALCULATION, + runIf = job == MAIN_CALCULATION, OneTimeWorkRequest.Builder(UpdateGraphWorker::class.java) .setInputData(Data.Builder().putString(JOB, job).putInt(PASS, CalculationWorkflow.ProgressData.DRAW_IOB.pass).build()) .build() ) .then( - job == MAIN_CALCULATION, + runIf = job == MAIN_CALCULATION, OneTimeWorkRequest.Builder(InvokeLoopWorker::class.java) .setInputData(dataWorkerStorage.storeInputData(InvokeLoopWorker.InvokeLoopData(cause))) .build() ) .then( - job == MAIN_CALCULATION, + runIf = job == MAIN_CALCULATION, OneTimeWorkRequest.Builder(UpdateWidgetWorker::class.java).build() ) .then( - job == MAIN_CALCULATION, + runIf = job == MAIN_CALCULATION, OneTimeWorkRequest.Builder(PreparePredictionsWorker::class.java) .setInputData(dataWorkerStorage.storeInputData(PreparePredictionsWorker.PreparePredictionsData(overviewData))) .build() diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt index 7766c8f855..c8d6f1fa23 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt @@ -57,6 +57,7 @@ class PrepareBasalDataWorker( val fromTime = data.overviewData.fromTime var time = fromTime while (time < endTime) { + if (isStopped) return Result.failure(workDataOf("Error" to "stopped")) val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0 rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_BASAL_DATA, progress.toInt(), null)) val profile = profileFunction.getProfile(time) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt index b8e2a2b92f..679dc2633f 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt @@ -158,6 +158,7 @@ class PrepareIobAutosensGraphDataWorker( val adsData = data.iobCobCalculator.ads.clone() while (time <= endTime) { + if (isStopped) return Result.failure(workDataOf("Error" to "stopped")) val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0 rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, progress.toInt(), null)) val profile = profileFunction.getProfile(time) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt index f9cb62ec66..22b8d1a0ad 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt @@ -58,6 +58,7 @@ class PrepareTemporaryTargetDataWorker( loop.lastRun?.constraintsProcessed?.let { endTime = max(it.latestPredictionsTime, endTime) } var time = fromTime while (time < endTime) { + if (isStopped) return Result.failure(workDataOf("Error" to "stopped")) val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0 rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, progress.toInt(), null)) val tt = repository.getTemporaryTargetActiveAt(time).blockingGet()