Open bplattenburg opened 5 days ago
Didn't think about this until now, but could this be something that is part of the existing Health tool?
@rajramsaroop That's a good question—should this tool be a HealthMetricProvider
, and if so, what would that look like?
My gut feeling is, "Yes, it makes sense," but I'd want to split that scope into a different story.
@rajramsaroop I thought about it a bit more, and I couldn't figure out what would constitute a useful unhealthy state as a HealthMetric
- if its disconnected
, then it won't sync out with the heartbeat anyway, so you'd already know, and both connectedIdle
and connectedSyncing
are healthy states.
At the risk of bike-shedding, the names becameConnectedAt
and lastConnectedAt
don't immediately disambiguate without further context.
These timestamps are designed to answer questions such as "how long since I was last successfully connected?" or "when was the last time my connection was interrupted?"
Both of those could be answered with a single lastConnectionStateChange
timestamp. If I'm currently connected, it will tell me when that connection was established. If I'm currently disconnected, it will tell me the last time I had a successful connection. Curious if there are other important questions that can't be answered by that variable?
I assume we already have a lastUpdateReceived
variable (or similar) to test the idleTimeoutInterval
@dhaikney I think thats generally accurate, the intent was to provide as many convenience accessors as possible, and align to what we just shipped over in https://github.com/getditto/ditto_flutter_tools.
We can revisit naming across all the platforms as long as we get it all lined up.
Create a new tool - DittoSyncStatusHelper
This tool allows the user to pass in a list of subscriptions and a handler, to which the "status" of the set of subscriptions is delivered. This "status" is either
disconnected
,connectedIdle
orconnectedSyncing
:disconnected
means the presence graph has both noremotePeers
andlocalPeer.isConnectedToDittoCloud
isfalse
(tracked internally via anisConnected
bool updated by observing the presence graph)connectedIdle
means there have been no new query results for the set of subscriptions in the previousidleTimeoutInterval
, which defaults to 1 secondconnectedSyncing
means there has been at least one update to at least one subscription in the previousidleTimeoutInterval
, which defaults to 1 secondThe tool works by internally creating store observers matching each subscription passed in, and then tracking a
lastUpdated
date every time any results flow out of the observer, updating the date.For convenience, also provide the following timestamps:
becameConnectedAt
- the last time isConnected was truebecameDisconnectedAt
- the last time isConnected went from true to falselastConnectedAt
- the last time isConnected went from false to trueThere is one important caveat to this tool that we should clearly call out in the documentation:
connectedIdle
but not have the latest data. This will only come up in p2p sync scenarios, however, not when only doing cloud sync—any Big Peers would always be subscribed to everything.