Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DittoSyncStatusHelper #161

Open
bplattenburg opened this issue Nov 16, 2024 · 5 comments · May be fixed by #162
Open

DittoSyncStatusHelper #161

bplattenburg opened this issue Nov 16, 2024 · 5 comments · May be fixed by #162
Assignees

Comments

@bplattenburg
Copy link
Member

bplattenburg commented Nov 16, 2024

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:

  • disconnected means the presence graph has both no remotePeers and localPeer.isConnectedToDittoCloud is false (tracked internally via an isConnected bool updated by observing the presence graph)
  • connectedIdle means there have been no new query results for the set of subscriptions in the previous idleTimeoutInterval, which defaults to 1 second
  • connectedSyncing means there has been at least one update to at least one subscription in the previous idleTimeoutInterval, which defaults to 1 second

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.
@bplattenburg bplattenburg self-assigned this Nov 16, 2024
@bplattenburg bplattenburg linked a pull request Nov 16, 2024 that will close this issue
@rajramsaroop
Copy link

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

@bplattenburg
Copy link
Member Author

bplattenburg commented Nov 19, 2024

@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
Copy link
Member Author

@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
Copy link

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants