opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
50 stars 39 forks source link

Inconsistent sync complete toast #2942

Open f-odhiambo opened 6 months ago

f-odhiambo commented 6 months ago

Describe the bug After clicking sync(On the registers menu) two toast messages are shown "Sync complete" then a second later "Syncing"

To Reproduce Steps to reproduce the behavior:

  1. Log in to Bidan, Eir and Cadre
  2. Click on the menu on the top left corner
  3. Click on sync
  4. Two toast messages are shown Sync complete the Syncing a second later(See attached screen cast)

Expected behavior After clicking on sync the toast message syncing should be shown then later sync complete should show.

https://github.com/ona-health/sid-dto-fhir-resources/assets/73172427/c469525b-257e-4a31-be2d-50abaccff563

kelvin-ngure commented 5 months ago

@f-odhiambo What is happening is intentional due to a missing feature that is coming soon from the SDK. This SyncJobStatus file will show you the new ENQUEUED state coming soon

While there is an ENQUEUED WorkState for scheduled jobs, there is no such SyncJobStatus and as a result, when a job is enqueued, the RegisterFragment is instructed to mark it as FINISHED.

Since every job enters an ENQUEUED phase regardless of whether it is a periodicSync or oneTimeSync, the "Sync Complete" toast shows up immediately the jobs are enqueued. The oneTimeSync jobs quickly jump into STARTED state and so you see the "Syncing" on the UI. Then once the oneTimeSync is complete, the "Sync Complete" toast shows up for the second time

I've added some Timber entries in the code to demonstrate image (1)

kelvin-ngure commented 5 months ago

While looking at this, I spotted what I believe to be a bug or something that can make spotting sync issues harder. When you initially start the app, the sync ends in a FAILED state that is preceded by a GLITCH state. On the UI, the "Sync Completed" toast shows up but then a sync retry begins. The retry is expected since GLITCH should prompt a retry. I will look into the flow and figure out why the "Sync Complete" toast shows up even on failure when a GLITCH happens right before FAILED

image

@f-odhiambo @dubdabasoduba please let me know if we should show a "Sync Failed. Retrying..." toast or something during a Glitch as there is no handler for the GLITCH status

I've added some Timber entries in the code to demonstrate

The below shows that both types of job do enter an ENQUEUE phase so there probably be a different logic to handle them image

The below shows the GLITCH phase (I have added a handler for it in the code). I am currently getting 403 and 502 errors on SID-EIR (currently following up with @f-odhiambo on that- my credentials may be bad or something else) and that is likely what causes the GLITCH. The retry is expected and that's why you see the manual oneTimeSync restart. However, as noted above, I will fix the issue where the UI shows "Sync Complete" even during a GLITCH and subsequent FAILED state

image

We may also need to decide how many times the app should retry sync after failure. It appears to retry indefinitely. Let me know if that is the case

ndegwamartin commented 5 months ago

Related ticket here https://github.com/opensrp/fhircore/issues/2947

dubdabasoduba commented 5 months ago

@kelvin-ngure did you stop getting the 403s and 502s mentioned in the comment above?

kelvin-ngure commented 5 months ago

@dubdabasoduba no. I just sent you some logs

kelvin-ngure commented 4 months ago

@ndegwamartin @f-odhiambo from What I see in the upgrade PR. To fix this, we would first need to migrate from using SyncJobStatus to using CurrentSyncJobStatus which has both work state and SyncJobStatus state representations. Is that migration something we are planning to do?

ndegwamartin commented 4 months ago

@kelvin-ngure yeah this needs to be done. Created a ticket here to track this https://github.com/opensrp/fhircore/issues/3059. Feel free to update the ticket with other info needed.

ndegwamartin commented 3 months ago

This is still blocked, see https://github.com/google/android-fhir/issues/2472