Skip to content

Commit d6f247b

Browse files
authored
Merge pull request #3875 from Navid200/Navid_2025_01_04
Notify and log failure to upload to all intended Nightscout sites
2 parents 0addc89 + 94a3917 commit d6f247b

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/services/DailyIntentService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue;
2121
import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue;
2222
import com.eveningoutpost.dexdrip.utilitymodels.IncompatibleApps;
23+
import com.eveningoutpost.dexdrip.utilitymodels.NightscoutUploader;
2324
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
2425
import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue;
2526
import com.eveningoutpost.dexdrip.cloud.backup.Backup;
@@ -173,6 +174,12 @@ public static synchronized void work() {
173174
Log.e(TAG, "Exception in SettingsValidation: " + e);
174175
}
175176

177+
try {
178+
NightscoutUploader.notifyInconsistentMultiSiteUpload();
179+
} catch (Exception e) {
180+
Log.e(TAG, "Exception in Nightscout multi site upload failure log: " + e);
181+
}
182+
176183
Log.i(TAG, "DailyIntentService onHandleIntent exiting after " + ((JoH.tsl() - start) / 1000) + " seconds");
177184
//} else {
178185
// Log.e(TAG, "DailyIntentService exceeding rate limit");

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutUploader.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.eveningoutpost.dexdrip.Home;
1010
import com.eveningoutpost.dexdrip.MegaStatus;
11+
import com.eveningoutpost.dexdrip.R;
1112
import com.eveningoutpost.dexdrip.models.BgReading;
1213
import com.eveningoutpost.dexdrip.models.BloodTest;
1314
import com.eveningoutpost.dexdrip.models.Calibration;
@@ -463,7 +464,9 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat
463464
Log.e(TAG, "Unable to process API Base URL: " + e);
464465
return false;
465466
}
467+
// Starting a loop run; resetting local failure and success flags
466468
boolean any_successes = false;
469+
boolean any_failures = false;
467470
for (String baseURI : baseURIs) {
468471
try {
469472
baseURI = TryResolveName(baseURI);
@@ -496,18 +499,36 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat
496499
} else {
497500
doLegacyRESTUploadTo(nightscoutService, glucoseDataSets);
498501
}
499-
any_successes = true;
502+
any_successes = true; // There has been a success
500503
last_success_time = JoH.tsl();
501504
last_exception_count = 0;
502505
last_exception_log_count = 0;
503506
} catch (Exception e) {
504507
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
505509
handleRestFailure(msg);
506510
}
507511
}
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+
}
508518
return any_successes;
509519
}
510520

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+
511532
private void doLegacyRESTUploadTo(NightscoutService nightscoutService, List<BgReading> glucoseDataSets) throws Exception {
512533
for (BgReading record : glucoseDataSets) {
513534
Response<ResponseBody> r = nightscoutService.upload(populateLegacyAPIEntry(record)).execute();

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,8 @@
12251225
<string name="summary_cloud_storage_api_download_enable">Also try to download treatments from Nightscout</string>
12261226
<string name="title_cloud_storage_api_download_enable">Download treatments</string>
12271227
<string name="title_cloud_storage_api_download_from_xdrip">Skip items from xDrip</string>
1228+
<string name="nightscout_upload_failure_backfill_required">Uploads have not succeeded for all sites. Backfill is recommended. First failure: %1$s</string>
1229+
<string name="title_nightscout_upload_failure_backfill_required">Inconsistent Multi-Site Nightscout Upload</string>
12281230
<string name="summary_cloud_storage_api_download_from_xdrip">Avoid downloading items uploaded by xDrip</string>
12291231
<string name="summary_bluetooth_meter_for_calibrations_auto">Calibrate using new blood glucose readings if the conditions appear right to do so without asking confirmation (experimental)</string>
12301232
<string name="title_bluetooth_meter_for_calibrations_auto">Automatic Calibration</string>
@@ -1237,6 +1239,8 @@
12371239
<string name="title_send_treatments_to_nightscout">Upload treatments</string>
12381240
<string name="summary_warn_nightscout_failures">Display and sound a notification if Nightscout upload is failing.</string>
12391241
<string name="title_warn_nightscout_failures">Alert on failures</string>
1242+
<string name="summary_warn_nightscout_multi_site_upload_failure">xDrip clears the upload queue even if only one site has a successful upload, leaving others incomplete. This notifies you, allowing you to backfill as needed.</string>
1243+
<string name="title_warn_nightscout_multi_site_upload_failure">Alert on multi-site upload failure</string>
12401244
<string name="summary_nightscout_device_append_source_info">For Dex, sends collector type (e.g. OB1) and reading backfill status (for native) to Nightscout.</string>
12411245
<string name="title_nightscout_device_append_source_info">Append source info to device name</string>
12421246
<string name="summary_tap_to_send_historical_data">Tap to send historical data to Nightscout</string>

app/src/main/res/xml/pref_data_sync.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
android:key="nightscout_device_append_source_info"
123123
android:summary="@string/summary_nightscout_device_append_source_info"
124124
android:title="@string/title_nightscout_device_append_source_info" />
125+
<CheckBoxPreference
126+
android:defaultValue="true"
127+
android:key="warn_nightscout_multi_site_upload_failure"
128+
android:summary="@string/summary_warn_nightscout_multi_site_upload_failure"
129+
android:title="@string/title_warn_nightscout_multi_site_upload_failure" />
125130
<Preference
126131
android:key="back_fill_data_activity_intent_key"
127132
android:summary="@string/summary_tap_to_send_historical_data"

0 commit comments

Comments
 (0)