Worker DB pruning
This commit is contained in:
parent
3093a84d65
commit
516630215c
1 changed files with 19 additions and 5 deletions
|
@ -7,10 +7,8 @@ import android.app.PendingIntent.FLAG_IMMUTABLE
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.*
|
||||||
import androidx.work.WorkManager
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import androidx.work.Worker
|
|
||||||
import androidx.work.WorkerParameters
|
|
||||||
import dagger.android.DaggerBroadcastReceiver
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.BuildConfig
|
import info.nightscout.androidaps.BuildConfig
|
||||||
|
@ -55,7 +53,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
class KeepAliveWorker(
|
class KeepAliveWorker(
|
||||||
context: Context,
|
private val context: Context,
|
||||||
params: WorkerParameters
|
params: WorkerParameters
|
||||||
) : Worker(context, params) {
|
) : Worker(context, params) {
|
||||||
|
|
||||||
|
@ -96,10 +94,26 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
checkPump()
|
checkPump()
|
||||||
checkAPS()
|
checkAPS()
|
||||||
maintenancePlugin.deleteLogs(30)
|
maintenancePlugin.deleteLogs(30)
|
||||||
|
workerDbStatus()
|
||||||
|
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When Worker DB grows too much, work operations become slow
|
||||||
|
// Library is cleaning DB every 7 days which may not be sufficient for NSClient full sync
|
||||||
|
private fun workerDbStatus() {
|
||||||
|
val workQuery = WorkQuery.Builder
|
||||||
|
.fromStates(listOf(WorkInfo.State.FAILED, WorkInfo.State.SUCCEEDED))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val workInfo: ListenableFuture<List<WorkInfo>> = WorkManager.getInstance(context).getWorkInfos(workQuery)
|
||||||
|
aapsLogger.debug(LTag.CORE, "WorkManager size is ${workInfo.get().size}")
|
||||||
|
if (workInfo.get().size > 1000) {
|
||||||
|
WorkManager.getInstance(context).pruneWork()
|
||||||
|
aapsLogger.debug(LTag.CORE, "WorkManager pruning ....")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Usually deviceStatus is uploaded through LoopPlugin after every loop cycle.
|
// Usually deviceStatus is uploaded through LoopPlugin after every loop cycle.
|
||||||
// if there is no BG available, we have to upload anyway to have correct
|
// if there is no BG available, we have to upload anyway to have correct
|
||||||
// IOB displayed in NS
|
// IOB displayed in NS
|
||||||
|
|
Loading…
Add table
Reference in a new issue