getditto / DittoSwiftTools

Diagnostic and Debugging Tools for DittoSwift
MIT License
9 stars 2 forks source link

DittoSyncStatusHelper #161

Open bplattenburg opened 5 days ago

bplattenburg commented 5 days ago

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 or connectedSyncing:

The 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:

  1. becameConnectedAt - the last time isConnected was true
  2. becameDisconnectedAt - the last time isConnected went from true to false
  3. lastConnectedAt - the last time isConnected went from false to true

There is one important caveat to this tool that we should clearly call out in the documentation:

  1. There are no guarantees that any remote peers you are connected to have subscriptions that match yours. It is fully possible to be 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.
rajramsaroop commented 2 days ago

Didn't think about this until now, but could this be something that is part of the existing Health tool?

bplattenburg commented 2 days ago

@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.

bplattenburg commented 1 day ago

@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.

dhaikney commented 1 day ago

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

bplattenburg commented 1 day ago

@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.