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.Intent
|
||||
import android.os.SystemClock
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.*
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import dagger.android.DaggerBroadcastReceiver
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.BuildConfig
|
||||
|
@ -55,7 +53,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
|||
}
|
||||
|
||||
class KeepAliveWorker(
|
||||
context: Context,
|
||||
private val context: Context,
|
||||
params: WorkerParameters
|
||||
) : Worker(context, params) {
|
||||
|
||||
|
@ -96,10 +94,26 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
|||
checkPump()
|
||||
checkAPS()
|
||||
maintenancePlugin.deleteLogs(30)
|
||||
workerDbStatus()
|
||||
|
||||
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.
|
||||
// if there is no BG available, we have to upload anyway to have correct
|
||||
// IOB displayed in NS
|
||||
|
|
Loading…
Reference in a new issue