androidiosazurexamarinazure-mobile-services

Azure App Service - Offline Sync - PullAsync Transaction


I'm working on an App which uses Xamarin.Forms and Azure App Service. The user must explicitly execute a data sync. When the user starts a data sync a lot of this methods are executed to get the current data from the server:

 await this.ISyncTable.PullAsync(queryId, query, cancellationToken).ConfigureAwait(false);

My problem: The application can get into an inconsistent state. For example when the user closes the App before the data sync is completed. In this state the App is not usable.

Edit:

To make it easier to understand: Let's assume i have a table "ToDoItem" and "ToDoCategory". The user starts a data sync. The data sync runs and the all ToDoItems are successfully retrieved . In the next step the data sync will get the ToDoCategories (another call to PullAsync) but before this the user closes the app. Now i have all ToDoItems but no ToDoCategories. But the App is not useable with no ToDoCategories. This is a really simple example. The data structure is much more complex in the real project. There are a lot of dependencies between the entities.

It is no solution to log the sync error / cancellation and prompt the user at the next app start for another sync. Assume on the next app start the user has no internet connection and cannot perform a data sync. I cannot lock the app until the next successful data sync.

Is there a way to run multiple PullAsync operations in a transaction?


Solution

  • Is there a way to run multiple PullAsync operations in a transaction?

    Short answer is no, there isn't. Set a flag in when all your PullAsync operations are complete, or keep track of which tables have synced successfully.

    It is no solution to log the sync error / cancellation and prompt the user at the next app start for another sync. Assume on the next app start the user has no internet connection and cannot perform a data sync. I cannot lock the app unitl the next successful data sync.

    What is your app's expected behavior on the second run if the user started the sync but then left the app before sync completed? Finish the sync? Prompt the user to start again?

    Also consider the app could probably continue syncing in the background after the user has left. In iOS you have to coordinate with the operating system using UIApplication beginBackgroundTaskWithExpirationHandler.