msupply-foundation / msupply-cold-chain

Android application for viewing and monitoring temperatures of fridges
GNU General Public License v3.0
3 stars 3 forks source link

Sync Order causes problems with open-mSupply #290

Closed jmbrunskill closed 7 months ago

jmbrunskill commented 7 months ago

Describe the bug

Cold chain tries to sync sensors, then logs, then breaches in that order. However because temperature logs contain links to breaches, the logs need to be sent last

      yield put(SyncAction.syncSensors(`${serverUrl}/${ENDPOINT.SENSOR}`));
      yield take([SyncAction.syncSensorsSuccess, SyncAction.syncSensorsFailure]);
      yield put(SyncAction.syncTemperatureLogs(`${serverUrl}/${ENDPOINT.TEMPERATURE_LOG}`));
      yield take([SyncAction.syncTemperatureLogsSuccess, SyncAction.syncTemperatureLogsFailure]);
      yield put(SyncAction.syncTemperatureBreaches(`${serverUrl}/${ENDPOINT.TEMPERATURE_BREACH}`));

To Reproduce Steps to reproduce the behavior:

  1. Link CCA to open mSupply
  2. Disable syncing while creating temperature breaches
  3. Create temperature breaches
  4. Turn on sync
  5. See errors in Open mSupply Logs
  6. See the temperature logs linked to the breach are missing
2024-02-08 15:13:43.401220000 [ERROR] <server::cold_chain::temperature_log:94>:"Unable to insert temperature log DatabaseError(ForeignKeyViolation(\"\\\"FOREIGN KEY constraint failed\\\"\"))" TemperatureLog { id: "fb405baf-e447-4c56-b83c-b077b0755156", temperature: 24.1, unix_timestamp: 1702350772, sensor_id: "1d235289-4984-49e1-ae99-944eda2eefc6", temperature_breach_id: Some("c5b90893-d411-4fb8-

Expected behavior Logs should sync

Additional context Add any other context about the problem here.

marthakeezy commented 3 months ago

Mark confirmed the issue has been Dev build tested, so moving to Done ✅ :) Will keep an eye on general log synchronisation and reopen individual issues should any problems occur!