Sync
Developer checklist for adding a new entity to be synced to mobile
Assuming that you have defined your JPA Entity and database table; and defined Entity in avni-models. The following is meant to be a checklist and not a complete guide.
Avni Server
- In simple cases you can extend your EntityRepository from
FindByLastModifiedDateTime
. You can look at a more complex example hereorg.avni.web.IndividualController#getIndividualsByOperatingIndividualScope
. In a simple case, the sync is performed only based on lastModifiedDateTime. In complex cases there may be additional filters - In
SyncController
add your entity service.
Sync data between Avni Client and Server
Sync between Avni Client and Server is initiated by the Client and could be of following types:
- Manual Sync(User triggered, upload and fetch data)
As part of manual sync, we'll first replace the "background-sync" job with a "dummy sync" job, perform manual-sync and then, replace the "dummy sync" job again with "background-sync" job.
In react-native-background-worker, when we schedule a job with same jobKey(Name) as an existing job, it replaces the old one with new one. Therefore, above specified steps are supposed to fulfill our need to NOT run background-sync in parallel with manual-sync.
This is done, as we do not have a way to cancel jobs by name directly in react-native-background-worker. We could only cancel by id, but we do not want to store job id in db. - Automatic Sync (Periodic trigger)
- Complete Sync (upload and fetch data)
- Partial Sync (Only upload of data)

Pictorial representation of different Sync workflows in Avni-Client
Updated 4 months ago