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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -115,6 +116,8 @@ public class NightscoutUploader {
public static final int FAIl_COUNT_NOTIFICATION = FAIL_NOTIFICATION_PERIOD / 60 / 5 - 1; // Number of 5-minute read cycles corresponding to notification period
public static final int FAIL_LOG_PERIOD = 6 * 60 * 60; // FAILED upload/download log will be shown if there is no upload/download for 6 hours.
public static final int FAIL_COUNT_LOG = FAIL_LOG_PERIOD / 60 / 5 - 1; // Number of 5-minute read cycles corresponding to log period
public static boolean inconsistentMultiSteUpload = false; // False if all site uploads fail or all succeed. True only if there is inconsistent upload success.
public static long firstInconsistentMultiSiteUploadTime;

private Context mContext;
private Boolean enableRESTUpload;
Expand Down Expand Up @@ -500,14 +503,31 @@ private boolean doRESTUpload(SharedPreferences prefs, List<BgReading> glucoseDat
last_success_time = JoH.tsl();
last_exception_count = 0;
last_exception_log_count = 0;
} catch (Exception e) {
} catch (Exception e) { // There has been a failure.
String msg = "Unable to do REST API Upload: " + e.getMessage() + " marking record: " + (any_successes ? "succeeded" : "failed");
handleRestFailure(msg);
if (any_successes) { // If there has been a success
if (!inconsistentMultiSteUpload) {
firstInconsistentMultiSiteUploadTime = JoH.tsl();
}
inconsistentMultiSteUpload = true; // There has been success as well as failure.
}
}
}
return any_successes;
}

public static void notifyInconsistentMultiSiteUpload() {
if (inconsistentMultiSteUpload) { // We need to inform the user that even though there has been a failure to upload, the queue has been cleared.
// Therefore, the only way to complete the intended upload is to backfill manually.
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));
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