|
8 | 8 |
|
9 | 9 | import com.eveningoutpost.dexdrip.Home; |
10 | 10 | import com.eveningoutpost.dexdrip.MegaStatus; |
| 11 | +import com.eveningoutpost.dexdrip.R; |
11 | 12 | import com.eveningoutpost.dexdrip.models.BgReading; |
12 | 13 | import com.eveningoutpost.dexdrip.models.BloodTest; |
13 | 14 | import com.eveningoutpost.dexdrip.models.Calibration; |
@@ -463,7 +464,9 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat |
463 | 464 | Log.e(TAG, "Unable to process API Base URL: " + e); |
464 | 465 | return false; |
465 | 466 | } |
| 467 | + // Starting a loop run; resetting local failure and success flags |
466 | 468 | boolean any_successes = false; |
| 469 | + boolean any_failures = false; |
467 | 470 | for (String baseURI : baseURIs) { |
468 | 471 | try { |
469 | 472 | baseURI = TryResolveName(baseURI); |
@@ -496,18 +499,36 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat |
496 | 499 | } else { |
497 | 500 | doLegacyRESTUploadTo(nightscoutService, glucoseDataSets); |
498 | 501 | } |
499 | | - any_successes = true; |
| 502 | + any_successes = true; // There has been a success |
500 | 503 | last_success_time = JoH.tsl(); |
501 | 504 | last_exception_count = 0; |
502 | 505 | last_exception_log_count = 0; |
503 | 506 | } catch (Exception e) { |
504 | 507 | String msg = "Unable to do REST API Upload: " + e.getMessage() + " marking record: " + (any_successes ? "succeeded" : "failed"); |
| 508 | + any_failures = true; // There has been a failure |
505 | 509 | handleRestFailure(msg); |
506 | 510 | } |
507 | 511 | } |
| 512 | + if (any_successes && any_failures) { // Only if there has been success as well as failure (inconsistent upload) |
| 513 | + if (!PersistentStore.getBoolean(TAG + "_inconsistentMultiSteUpload")) { // If there had been no inconsistent uploads yet, which makes this the first |
| 514 | + PersistentStore.setLong(TAG + "_firstInconsistentMultiSiteUploadTime", JoH.tsl()); // Record this time as the time of the first inconsistent upload |
| 515 | + } |
| 516 | + PersistentStore.setBoolean(TAG + "_inconsistentMultiSteUpload", true); // There has been inconsistent upload and we have recorded the time. Let's set the flag. |
| 517 | + } |
508 | 518 | return any_successes; |
509 | 519 | } |
510 | 520 |
|
| 521 | + public static void notifyInconsistentMultiSiteUpload() { |
| 522 | + long firstInconsistentMultiSiteUploadTime = PersistentStore.getLong(TAG + "_firstInconsistentMultiSiteUploadTime"); // Updating the local representation of the last inconsistent upload time |
| 523 | + if (PersistentStore.getBoolean(TAG + "_inconsistentMultiSteUpload")) { // If there has been a failure to upload and the queue has been cleared |
| 524 | + if (Pref.getBooleanDefaultFalse("warn_nightscout_multi_site_upload_failure")) { // Issue notification only if enabled |
| 525 | + JoH.showNotification(xdrip.gs(R.string.title_nightscout_upload_failure_backfill_required), null, null, Constants.NIGHTSCOUT_ERROR_NOTIFICATION_ID, null, false, false, null, null, xdrip.gs(R.string.nightscout_upload_failure_backfill_required, JoH.dateTimeText(firstInconsistentMultiSiteUploadTime)), true); |
| 526 | + } |
| 527 | + UserError.Log.uel(TAG, "Inconsistent Multi-site Nightscout upload - Backfill recommended - First failure: " + JoH.dateTimeText(firstInconsistentMultiSiteUploadTime)); |
| 528 | + PersistentStore.setBoolean(TAG + "_inconsistentMultiSteUpload", false); // We have notified. Clearing the flag |
| 529 | + } |
| 530 | + } |
| 531 | + |
511 | 532 | private void doLegacyRESTUploadTo(NightscoutService nightscoutService, List<BgReading> glucoseDataSets) throws Exception { |
512 | 533 | for (BgReading record : glucoseDataSets) { |
513 | 534 | Response<ResponseBody> r = nightscoutService.upload(populateLegacyAPIEntry(record)).execute(); |
|
0 commit comments