Amplify-js: Datastore - sync status

Created on 30 Jan 2020  路  13Comments  路  Source: aws-amplify/amplify-js

Hi, it's actually difficult to know which behavior will have Datastore and we would like to notify our users in which mode is currently our app.
It will be great if Datastore could notify its status :

  • DELTA-SYNC (receiving all stored data since last connection)
  • ONLINE (Datastore is online - Data are pushed remotely and data from Appsync are received through subscriptions)
  • OFFLINE (Datastore uses local storage)
  • FULL-SYNC

This status may be quite different from network status since we can imagine that even if the user has a connection but the connection is poor, Datastore is in OFFLINE mode waiting for a better connection

DataStore feature-request

Most helpful comment

We're very close to releasing this, possibly in the next week or so.

All 13 comments

It may help during development and testing too

Thank you @mlecoq, this is a good use case that we've talked about, we'll be tracking this as a feature request

@mlecoq would a solution where we emitted events to Hub work for you? https://aws-amplify.github.io/docs/js/hub

@undefobj sure, I鈥檝e never used Hub but after reading the docs it looks to be a good fit

Ok great we're still looking at some designs here but this is good feedback. Thanks.

I'm going to add an additional use case here: When booting the app we ask the user for some details about themselves. How do we know whether that data exists so that we can know whether to ask ? Query will return nothing until sync is finished, even if the data exists.

What's worse, is that now that we mis-detect this we have customers with multiple copies of what is supposed to be a single settings object and we have to go through and clean them up and merge them manually.

This is actually a very bad problem because it can result in bad data shown to the customer and bad records in the database, and a bad customer experience.

It's also very easy to reproduce. Clear your browser data, login with a different browser or a different computer.

My use case: Upon logging out, my app clears the DataStore. I want to warn users before logging out that they may lose content if a sync has not been completed. For example if they are still offline, have created content offline, but are attempting to logout.

Are there any updates on this issue? Is it a work in progress? We are running into similar problems that could be solved if we would be able to know the sync status.

Would be especially great to be able to know if the initial sync finished.

Many thanks.

Yeah I definitely think it's important to be able to inform the user if data is still loading etc and the results are incomplete or not yet available.

@manueliglesias I would love to hear if this is still on the immediate roadmap as I see there are _a lot_ of competing demands at the moment for the DataStore team, so it would be good to have realistic expectations here.

We're very close to releasing this, possibly in the next week or so.

That is awesome. Thanks for the update @undefobj.

Can there also be a state for 'something went wrong (e.g. permissions on subscribe) and the SubscriptionProcessor threw an exception and isn't currently running?' Because then calls to DataStore silently succeed but will never read/write from the backend - and digging through the debug logs in the console is a giant pain.

The hub channel of the datastore is not listed in the documentation (https://docs.amplify.aws/lib/utilities/hub/q/platform/js#channels) please note:

The channel is datastore

Hub.listen ("datastore", (data) => {
        console.log ('A new event has happened:', JSON.stringify(data));
 })
await DataStore.clear();
await DataStore.start();



md5-f34c8f5ff3242f35d7f0f1a6b9ee1dfe



A new event has happened:  {"channel":"datastore","payload":{"event":"storageSubscribed"},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"networkStatus","data":{"active":true}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"outboxStatus","data":{"isEmpty":true}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"subscriptionsEstablished"},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"syncQueriesStarted","data":{"models":["ModelX","ModelY","ModelLala"]}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"modelSynced","data":{"isFullSync":true,"isDeltaSync":false,"counts":{"new":5,"updated":0,"deleted":2}}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"modelSynced","data":{"isFullSync":true,"isDeltaSync":false,"counts":{"new":296,"updated":0,"deleted":2}}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"modelSynced","data":{"isFullSync":true,"isDeltaSync":false,"counts":{"new":8155,"updated":0,"deleted":0}}},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"syncQueriesReady"},"source":"","patternInfo":[]}

A new event has happened:  {"channel":"datastore","payload":{"event":"ready"},"source":"","patternInfo":[]}
Was this page helpful?
0 / 5 - 0 ratings