Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify and log failures to upload to Nightscout consistently #3875

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue;
import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue;
import com.eveningoutpost.dexdrip.utilitymodels.IncompatibleApps;
import com.eveningoutpost.dexdrip.utilitymodels.NightscoutUploader;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue;
import com.eveningoutpost.dexdrip.cloud.backup.Backup;
Expand Down Expand Up @@ -173,6 +174,12 @@ public static synchronized void work() {
Log.e(TAG, "Exception in SettingsValidation: " + e);
}

try {
NightscoutUploader.notifyInconsistentMultiSiteUpload();
} catch (Exception e) {
Log.e(TAG, "Exception in Nightscout multi site upload failure log: " + e);
}

Log.i(TAG, "DailyIntentService onHandleIntent exiting after " + ((JoH.tsl() - start) / 1000) + " seconds");
//} else {
// Log.e(TAG, "DailyIntentService exceeding rate limit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.MegaStatus;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.BloodTest;
import com.eveningoutpost.dexdrip.models.Calibration;
Expand Down Expand Up @@ -463,7 +464,9 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat
Log.e(TAG, "Unable to process API Base URL: " + e);
return false;
}
// Starting a loop run; resetting local failure and success flags
boolean any_successes = false;
boolean any_failures = false;
for (String baseURI : baseURIs) {
try {
baseURI = TryResolveName(baseURI);
Expand Down Expand Up @@ -496,18 +499,36 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat
} else {
doLegacyRESTUploadTo(nightscoutService, glucoseDataSets);
}
any_successes = true;
any_successes = true; // There has been a success
last_success_time = JoH.tsl();
last_exception_count = 0;
last_exception_log_count = 0;
} catch (Exception e) {
String msg = "Unable to do REST API Upload: " + e.getMessage() + " marking record: " + (any_successes ? "succeeded" : "failed");
any_failures = true; // There has been a failure
handleRestFailure(msg);
}
}
if (any_successes && any_failures) { // Only if there has been success as well as failure (inconsistent upload)
if (!PersistentStore.getBoolean(TAG + "inconsistentMultiSteUpload")) { // If there had been no inconsistent uploads yet, which makes this the first
PersistentStore.setLong(TAG + "firstInconsistentMultiSiteUploadTime", JoH.tsl()); // Record this time as the time of the first inconsistent upload
}
PersistentStore.setBoolean(TAG + "inconsistentMultiSteUpload", true); // There has been inconsistent upload and we have recorded the time. Let's set the flag.
}
return any_successes;
}

public static void notifyInconsistentMultiSiteUpload() {
long firstInconsistentMultiSiteUploadTime = PersistentStore.getLong(TAG + "firstInconsistentMultiSiteUploadTime"); // Updating the local representation of the last inconsistent upload time
if (PersistentStore.getBoolean(TAG + "inconsistentMultiSteUpload")) { // If there has been a failure to upload and the queue has been cleared
if (Pref.getBooleanDefaultFalse("warn_nightscout_multi_site_upload_failure")) { // Issue notification only if enabled
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);
}
UserError.Log.uel(TAG, "Inconsistent Multi-site Nightscout upload - Backfill recommended - First failure: " + JoH.dateTimeText(firstInconsistentMultiSiteUploadTime));
PersistentStore.setBoolean(TAG + "inconsistentMultiSteUpload", false); // We have notified. Clearing the flag
}
}

private void doLegacyRESTUploadTo(NightscoutService nightscoutService, List<BgReading> glucoseDataSets) throws Exception {
for (BgReading record : glucoseDataSets) {
Response<ResponseBody> r = nightscoutService.upload(populateLegacyAPIEntry(record)).execute();
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,8 @@
<string name="summary_cloud_storage_api_download_enable">Also try to download treatments from Nightscout</string>
<string name="title_cloud_storage_api_download_enable">Download treatments</string>
<string name="title_cloud_storage_api_download_from_xdrip">Skip items from xDrip</string>
<string name="nightscout_upload_failure_backfill_required">Uploads have not succeeded for all sites. Backfill is recommended. First failure: %1$s</string>
<string name="title_nightscout_upload_failure_backfill_required">Inconsistent Multi-Site Nightscout Upload</string>
<string name="summary_cloud_storage_api_download_from_xdrip">Avoid downloading items uploaded by xDrip</string>
<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>
<string name="title_bluetooth_meter_for_calibrations_auto">Automatic Calibration</string>
Expand All @@ -1237,6 +1239,8 @@
<string name="title_send_treatments_to_nightscout">Upload treatments</string>
<string name="summary_warn_nightscout_failures">Display and sound a notification if Nightscout upload is failing.</string>
<string name="title_warn_nightscout_failures">Alert on failures</string>
<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>
<string name="title_warn_nightscout_multi_site_upload_failure">Alert on multi-site upload failure</string>
<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>
<string name="title_nightscout_device_append_source_info">Append source info to device name</string>
<string name="summary_tap_to_send_historical_data">Tap to send historical data to Nightscout</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/pref_data_sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
android:key="nightscout_device_append_source_info"
android:summary="@string/summary_nightscout_device_append_source_info"
android:title="@string/title_nightscout_device_append_source_info" />
<CheckBoxPreference
android:defaultValue="true"
android:key="warn_nightscout_multi_site_upload_failure"
android:summary="@string/summary_warn_nightscout_multi_site_upload_failure"
android:title="@string/title_warn_nightscout_multi_site_upload_failure" />
<Preference
android:key="back_fill_data_activity_intent_key"
android:summary="@string/summary_tap_to_send_historical_data"
Expand Down