NSCv3: improve scheduling

This commit is contained in:
Milos Kozak 2023-02-19 22:09:11 +01:00
parent 0af1966bcb
commit 853c08e5ef
3 changed files with 14 additions and 26 deletions

View file

@ -1,5 +0,0 @@
package info.nightscout.plugins.sync.nsShared.events
import info.nightscout.rx.events.Event
class EventNSClientResend(val reason: String) : Event()

View file

@ -27,7 +27,6 @@ import info.nightscout.interfaces.sync.NsClient
import info.nightscout.interfaces.sync.Sync
import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.NSClientFragment
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
@ -113,10 +112,6 @@ class NSClientPlugin @Inject constructor(
addToLog(event)
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNSClientResend::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ event -> resend(event.reason) }, fabricPrivacy::logException)
}
override fun onStop() {

View file

@ -38,7 +38,6 @@ import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.NSClientFragment
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
@ -223,10 +222,6 @@ class NSClientV3Plugin @Inject constructor(
addToLog(event)
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNSClientResend::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ event -> resend(event.reason) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNewHistoryData::class.java)
.observeOn(aapsSchedulers.io)
@ -234,17 +229,20 @@ class NSClientV3Plugin @Inject constructor(
runLoop = Runnable {
var refreshInterval = T.mins(5).msecs()
repository.getLastGlucoseValueWrapped().blockingGet().let {
// if last value is older than 5 min or there is no bg
if (it is ValueWrapper.Existing) {
if (it.value.timestamp < dateUtil.now() - T.mins(5).plus(T.secs(20)).msecs()) {
refreshInterval = T.mins(1).msecs()
executeLoop("MAIN_LOOP", forceNew = true)
if (nsClientSource.isEnabled())
repository.getLastGlucoseValueWrapped().blockingGet().let {
// if last value is older than 5 min or there is no bg
if (it is ValueWrapper.Existing) {
if (it.value.timestamp < dateUtil.now() - T.mins(5).plus(T.secs(20)).msecs()) {
refreshInterval = T.mins(1).msecs()
}
}
} else executeLoop("MAIN_LOOP", forceNew = true)
}
}
if (!sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true))
executeLoop("MAIN_LOOP", forceNew = true)
else
rxBus.send(EventNSClientNewLog("● TICK", ""))
handler.postDelayed(runLoop, refreshInterval)
rxBus.send(EventNSClientNewLog("● TICK", ""))
}
handler.postDelayed(runLoop, T.mins(2).msecs())
}
@ -554,9 +552,9 @@ class NSClientV3Plugin @Inject constructor(
override fun resend(reason: String) {
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true))
executeUpload("RESEND", forceNew = false)
executeUpload("START $reason", forceNew = true)
else
executeLoop("RESEND", forceNew = false)
executeLoop("START $reason", forceNew = true)
}
override fun pause(newState: Boolean) {