NSCv3: improve scheduling
This commit is contained in:
parent
0af1966bcb
commit
853c08e5ef
3 changed files with 14 additions and 26 deletions
|
@ -1,5 +0,0 @@
|
||||||
package info.nightscout.plugins.sync.nsShared.events
|
|
||||||
|
|
||||||
import info.nightscout.rx.events.Event
|
|
||||||
|
|
||||||
class EventNSClientResend(val reason: String) : Event()
|
|
|
@ -27,7 +27,6 @@ import info.nightscout.interfaces.sync.NsClient
|
||||||
import info.nightscout.interfaces.sync.Sync
|
import info.nightscout.interfaces.sync.Sync
|
||||||
import info.nightscout.plugins.sync.R
|
import info.nightscout.plugins.sync.R
|
||||||
import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
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.EventNSClientStatus
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
||||||
|
@ -113,10 +112,6 @@ class NSClientPlugin @Inject constructor(
|
||||||
addToLog(event)
|
addToLog(event)
|
||||||
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
|
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
|
||||||
}, fabricPrivacy::logException)
|
}, fabricPrivacy::logException)
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventNSClientResend::class.java)
|
|
||||||
.observeOn(aapsSchedulers.io)
|
|
||||||
.subscribe({ event -> resend(event.reason) }, fabricPrivacy::logException)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
|
|
@ -38,7 +38,6 @@ import info.nightscout.plugins.sync.R
|
||||||
import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
||||||
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
|
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
|
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.EventNSClientUpdateGuiData
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
||||||
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
|
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
|
||||||
|
@ -223,10 +222,6 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
addToLog(event)
|
addToLog(event)
|
||||||
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
|
aapsLogger.debug(LTag.NSCLIENT, event.action + " " + event.logText)
|
||||||
}, fabricPrivacy::logException)
|
}, fabricPrivacy::logException)
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventNSClientResend::class.java)
|
|
||||||
.observeOn(aapsSchedulers.io)
|
|
||||||
.subscribe({ event -> resend(event.reason) }, fabricPrivacy::logException)
|
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
.toObservable(EventNewHistoryData::class.java)
|
.toObservable(EventNewHistoryData::class.java)
|
||||||
.observeOn(aapsSchedulers.io)
|
.observeOn(aapsSchedulers.io)
|
||||||
|
@ -234,17 +229,20 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
|
|
||||||
runLoop = Runnable {
|
runLoop = Runnable {
|
||||||
var refreshInterval = T.mins(5).msecs()
|
var refreshInterval = T.mins(5).msecs()
|
||||||
repository.getLastGlucoseValueWrapped().blockingGet().let {
|
if (nsClientSource.isEnabled())
|
||||||
// if last value is older than 5 min or there is no bg
|
repository.getLastGlucoseValueWrapped().blockingGet().let {
|
||||||
if (it is ValueWrapper.Existing) {
|
// if last value is older than 5 min or there is no bg
|
||||||
if (it.value.timestamp < dateUtil.now() - T.mins(5).plus(T.secs(20)).msecs()) {
|
if (it is ValueWrapper.Existing) {
|
||||||
refreshInterval = T.mins(1).msecs()
|
if (it.value.timestamp < dateUtil.now() - T.mins(5).plus(T.secs(20)).msecs()) {
|
||||||
executeLoop("MAIN_LOOP", forceNew = true)
|
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)
|
handler.postDelayed(runLoop, refreshInterval)
|
||||||
rxBus.send(EventNSClientNewLog("● TICK", ""))
|
|
||||||
}
|
}
|
||||||
handler.postDelayed(runLoop, T.mins(2).msecs())
|
handler.postDelayed(runLoop, T.mins(2).msecs())
|
||||||
}
|
}
|
||||||
|
@ -554,9 +552,9 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
|
|
||||||
override fun resend(reason: String) {
|
override fun resend(reason: String) {
|
||||||
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true))
|
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true))
|
||||||
executeUpload("RESEND", forceNew = false)
|
executeUpload("START $reason", forceNew = true)
|
||||||
else
|
else
|
||||||
executeLoop("RESEND", forceNew = false)
|
executeLoop("START $reason", forceNew = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pause(newState: Boolean) {
|
override fun pause(newState: Boolean) {
|
||||||
|
|
Loading…
Reference in a new issue