flutter_workmanager
flutter_workmanager copied to clipboard
Is it possible to chain multiple tasks which execution depends on success of task before them?
I would like to use Work Manager to sync local database (mobile app) with remote database through post request to server. Mobile app is "offline first" which means that user can create objects in local database and use app without being connected to internet. Data will be synced (with post request to server) as Work Manager decides it is appropriate.
I was using this approach in Android development with Work Manager but I don't know how to use it with Flutter.
Here is the problem: Before I sync entries from one table (Car) in database (post request to server) I need to make sure that its dependencies tables are synced successfully first (Owner). I would like to do that with chaining Work Manager tasks in queue where task for syncing Owner data sends result signal to its child task (Car) and only if signal is successfully executed task, sync of child task (Car) is started.
Is this possible to do like here? https://developer.android.com/topic/libraries/architecture/workmanager/how-to/chain-work
WMs chaining of work is fantastic, but not supported by this plugin as there's no equivalent on iOS, really. However, you could schedule more work from within the callback dispatcher.
So, use this plugin to schedule the first part of your sync process, then let it schedule the next one and so forth. Do you think that'll do it?
his plugin to schedule the first part of your sync process, then let it schedule the
Sure. That seems doable. When Owner database table is synced with server (POST request followed by 201 status response) I should register new task for Car database table and similarly to rest of the tables.
One more question: Which method of flutter_workmanager package do you recommend I should use for this kind of task? I want syncing would work for iOS and Android. For now I'm using registerOneOffTask when clicking on button widget and sync happens immediately. It would be best for sync to happen every hour (if there is anything to sync). Thank you.
his plugin to schedule the first part of your sync process, then let it schedule the
Sure. That seems doable. When Owner database table is synced with server (POST request followed by 201 status response) I should register new task for Car database table and similarly to rest of the tables.
One more question: Which method of
flutter_workmanagerpackage do you recommend I should use for this kind of task? I want syncing would work for iOS and Android. For now I'm using registerOneOffTask when clicking on button widget and sync happens immediately. It would be best for sync to happen every hour (if there is anything to sync). Thank you.
Do not rely on sync to happen every hour on iOS, this can still be up to the discretion of the operating system, for example. This plugin supports both refresh tasks and the background fetch, check out the example for both!