provide Worker failure results

This commit is contained in:
Milos Kozak 2021-04-01 00:03:49 +02:00
parent cacf239d17
commit 2df8c4fc74
14 changed files with 62 additions and 47 deletions

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.food
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -55,7 +56,7 @@ class FoodPlugin @Inject constructor(
override fun doWork(): Result {
val foods = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
aapsLogger.debug(LTag.DATABASE, "Received Food Data: $foods")
var ret = Result.success()
@ -77,7 +78,7 @@ class FoodPlugin @Inject constructor(
repository.runTransactionForResult(SyncNsFoodTransaction(delFood))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while removing food", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also {
@ -91,7 +92,7 @@ class FoodPlugin @Inject constructor(
repository.runTransactionForResult(SyncNsFoodTransaction(food))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while adding/updating food", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -101,7 +102,7 @@ class FoodPlugin @Inject constructor(
}
} else {
aapsLogger.error(LTag.DATABASE, "Error parsing food", jsonFood.toString())
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to "Error parsing food"))
}
}
}

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.general.nsclient
import android.content.Context
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -52,10 +54,10 @@ class NSClientAddUpdateWorker(
override fun doWork(): Result {
val acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, true) && buildHelper.isEngineeringMode() || config.NSCLIENT
if (!acceptNSData) return Result.failure()
if (!acceptNSData) return Result.success()
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
var ret = Result.success()
var latestDateInReceivedData = 0L
@ -81,7 +83,7 @@ class NSClientAddUpdateWorker(
repository.runTransactionForResult(SyncNsBolusTransaction(bolus))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -105,7 +107,7 @@ class NSClientAddUpdateWorker(
repository.runTransactionForResult(SyncNsCarbsTransaction(carb))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -131,7 +133,7 @@ class NSClientAddUpdateWorker(
repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTarget))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -175,7 +177,7 @@ class NSClientAddUpdateWorker(
repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvent))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -36,14 +37,14 @@ class NSClientMbgWorker(
if (!acceptNSData) return ret
val mbgArray = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
for (i in 0 until mbgArray.length()) {
val nsMbg = NSMbg(mbgArray.getJSONObject(i))
if (!nsMbg.isValid()) continue
repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEventFromNsMbg(nsMbg)))
.doOnError {
aapsLogger.error("Error while saving therapy event", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also {

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -48,12 +49,12 @@ class NSClientRemoveWorker(
override fun doWork(): Result {
val acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, true) && buildHelper.isEngineeringMode() || config.NSCLIENT
if (!acceptNSData) return Result.failure()
if (!acceptNSData) return Result.success()
var ret = Result.success()
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
for (i in 0 until treatments.length()) {
val json = treatments.getJSONObject(i)
@ -64,7 +65,7 @@ class NSClientRemoveWorker(
repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTarget))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary target", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -84,7 +85,7 @@ class NSClientRemoveWorker(
repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvent))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while invalidating therapy event", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -101,7 +102,7 @@ class NSClientRemoveWorker(
repository.runTransactionForResult(SyncNsBolusTransaction(bolus))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while invalidating bolus", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -118,7 +119,7 @@ class NSClientRemoveWorker(
repository.runTransactionForResult(SyncNsCarbsTransaction(carbs))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->

View file

@ -9,6 +9,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.Constants
@ -180,8 +181,8 @@ class SmsCommunicatorPlugin @Inject constructor(
@Suppress("SpellCheckingInspection")
override fun doWork(): Result {
val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
val format = bundle.getString("format") ?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
val format = bundle.getString("format") ?: return Result.failure(workDataOf("Error" to "missing format in input data"))
val pdus = bundle["pdus"] as Array<*>
for (pdu in pdus) {
val message = SmsMessage.createFromPdu(pdu as ByteArray, format)

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.profile.ns
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
@ -96,7 +97,7 @@ class NSProfilePlugin @Inject constructor(
override fun doWork(): Result {
val profileString = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
nsProfilePlugin.profile = ProfileStore(injector, profileString)
nsProfilePlugin.storeNSProfile()
if (nsProfilePlugin.isEnabled()) {

View file

@ -6,6 +6,7 @@ import android.content.pm.PackageManager
import androidx.core.content.ContextCompat
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
@ -97,9 +98,9 @@ class DexcomPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!dexcomPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!dexcomPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
try {
val sourceSensor = when (bundle.getString("sensorType") ?: "") {
"G6" -> GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE
@ -107,7 +108,7 @@ class DexcomPlugin @Inject constructor(
else -> GlucoseValue.SourceSensor.DEXCOM_NATIVE_UNKNOWN
}
val glucoseValuesBundle = bundle.getBundle("glucoseValues")
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing glucoseValues"))
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
for (i in 0 until glucoseValuesBundle.size()) {
val glucoseValueBundle = glucoseValuesBundle.getBundle(i.toString())!!
@ -144,7 +145,7 @@ class DexcomPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, calibrations, sensorStartTime))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Dexcom App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -161,7 +162,7 @@ class DexcomPlugin @Inject constructor(
}
} catch (e: Exception) {
aapsLogger.error("Error while processing intent from Dexcom App", e)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to e))
}
return ret
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -68,9 +69,9 @@ class EversensePlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!eversensePlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!eversensePlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase"))
if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress"))
if (bundle.containsKey("glucoseLevel")) aapsLogger.debug(LTag.BGSOURCE, "glucoseLevel: " + bundle.getInt("glucoseLevel"))
@ -111,7 +112,7 @@ class EversensePlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Eversense App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->
@ -141,7 +142,7 @@ class EversensePlugin @Inject constructor(
))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -55,7 +56,7 @@ class GlimpPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!glimpPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!glimpPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
aapsLogger.debug(LTag.BGSOURCE, "Received Glimp Data: $inputData}")
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
@ -69,7 +70,7 @@ class GlimpPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Glimp App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -60,8 +61,8 @@ class MM640gPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!mM640gPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
val collection = inputData.getString("collection") ?: return Result.failure()
if (!mM640gPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
val collection = inputData.getString("collection") ?: return Result.failure(workDataOf("Error" to "missing collection"))
if (collection == "entries") {
val data = inputData.getString("data")
aapsLogger.debug(LTag.BGSOURCE, "Received MM640g Data: $data")
@ -87,7 +88,7 @@ class MM640gPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Eversense App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->
@ -98,7 +99,7 @@ class MM640gPlugin @Inject constructor(
}
} catch (e: JSONException) {
aapsLogger.error("Exception: ", e)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to e))
}
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
@ -117,7 +118,7 @@ class NSClientSourcePlugin @Inject constructor(
if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_autobackfill, true) && !dexcomPlugin.isEnabled()) return Result.success()
val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
try {
var latestDateInReceivedData: Long = 0
@ -141,7 +142,7 @@ class NSClientSourcePlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null, !nsClientSourcePlugin.isEnabled()))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from NSClient App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { result ->
@ -158,7 +159,7 @@ class NSClientSourcePlugin @Inject constructor(
}
} catch (e: Exception) {
aapsLogger.error("Unhandled exception", e)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to e))
}
// Objectives 0
sp.putBoolean(R.string.key_ObjectivesbgIsAvailableInNS, true)

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
@ -59,7 +60,7 @@ class PoctechPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!poctechPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!poctechPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
aapsLogger.debug(LTag.BGSOURCE, "Received Poctech Data $inputData")
try {
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
@ -80,7 +81,7 @@ class PoctechPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Poctech App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->
@ -91,7 +92,7 @@ class PoctechPlugin @Inject constructor(
}
} catch (e: JSONException) {
aapsLogger.error("Exception: ", e)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to e))
}
return ret
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -60,7 +61,7 @@ class TomatoPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!tomatoPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!tomatoPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
timestamp = inputData.getLong("com.fanqies.tomatofn.Extras.Time", 0),
@ -73,7 +74,7 @@ class TomatoPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Tomato App", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -72,9 +73,9 @@ class XdripPlugin @Inject constructor(
override fun doWork(): Result {
var ret = Result.success()
if (!xdripPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
if (!xdripPlugin.isEnabled(PluginType.BGSOURCE)) return Result.success()
val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure()
?: return Result.failure(workDataOf("Error" to "missing input data"))
aapsLogger.debug(LTag.BGSOURCE, "Received xDrip data: $bundle")
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
@ -90,7 +91,7 @@ class XdripPlugin @Inject constructor(
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Xdrip", it)
ret = Result.failure()
ret = Result.failure(workDataOf("Error" to it))
}
.blockingGet()
.also { savedValues ->