NSC: resolve ack crash
This commit is contained in:
parent
43cef1e7b6
commit
3472f0f83e
2 changed files with 16 additions and 3 deletions
|
@ -3,7 +3,9 @@ package info.nightscout.core.utils.worker
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.work.Worker
|
import androidx.work.Worker
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
|
import androidx.work.workDataOf
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -11,14 +13,21 @@ import javax.inject.Inject
|
||||||
abstract class LoggingWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
|
abstract class LoggingWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
|
|
||||||
init {
|
init {
|
||||||
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doWork(): Result =
|
override fun doWork(): Result =
|
||||||
doWorkAndLog().also {
|
try {
|
||||||
aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this::class.java}")
|
doWorkAndLog().also {
|
||||||
|
aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this::class.java}")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
fabricPrivacy.logException(e)
|
||||||
|
e.printStackTrace()
|
||||||
|
Result.failure(workDataOf("Error" to e.localizedMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun doWorkAndLog(): Result
|
abstract fun doWorkAndLog(): Result
|
||||||
|
|
|
@ -48,7 +48,11 @@ class NSClientAddAckWorker(
|
||||||
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
||||||
|
|
||||||
if (sp.getBoolean(R.string.key_ns_sync_slow, false)) SystemClock.sleep(1000)
|
if (sp.getBoolean(R.string.key_ns_sync_slow, false)) SystemClock.sleep(1000)
|
||||||
val ret = Result.success(workDataOf("ProcessedData" to ack.originalObject.toString()))
|
val ret = try {
|
||||||
|
Result.success(workDataOf("ProcessedData" to ack.originalObject.toString()))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Result.success(workDataOf("ProcessedData" to "huge record"))
|
||||||
|
}
|
||||||
|
|
||||||
when (ack.originalObject) {
|
when (ack.originalObject) {
|
||||||
is PairTemporaryTarget -> {
|
is PairTemporaryTarget -> {
|
||||||
|
|
Loading…
Reference in a new issue