diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt index 315a5e9957..5153dd95bf 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt @@ -4,6 +4,9 @@ import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.plugin.ActivePlugin import app.aaps.core.interfaces.profile.ProfileFunction +import app.aaps.core.interfaces.rx.bus.RxBus +import app.aaps.core.interfaces.rx.events.EventNSClientNewLog +import app.aaps.core.interfaces.rx.events.EventXdripNewLog import app.aaps.core.interfaces.sharedPreferences.SP import app.aaps.core.interfaces.sync.DataSyncSelector import app.aaps.core.interfaces.sync.DataSyncSelectorXdrip @@ -25,7 +28,8 @@ class DataSyncSelectorXdripImpl @Inject constructor( private val profileFunction: ProfileFunction, private val activePlugin: ActivePlugin, private val xdripBroadcast: Lazy, - private val appRepository: AppRepository + private val appRepository: AppRepository, + private val rxBus: RxBus ) : DataSyncSelectorXdrip { class QueueCounter( @@ -72,7 +76,17 @@ class DataSyncSelectorXdripImpl @Inject constructor( override fun queueSize(): Long = queueCounter.size() + private var running = false + private val sync = Any() + override suspend fun doUpload() { + synchronized(sync) { + if (running) { + rxBus.send(EventXdripNewLog("RUN", "Already running")) + return + } + running = true + } if (isEnabled) { processChangedGlucoseValues() processChangedBoluses() @@ -96,6 +110,7 @@ class DataSyncSelectorXdripImpl @Inject constructor( // not supported at the moment //processChangedProfileStore() } + running = false } override fun resetToNextFullSync() {