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

Fix expiration of remote commands #1639

Merged
merged 1 commit into from
Mar 15, 2022
Merged
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
19 changes: 17 additions & 2 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,21 @@ extension DeviceDataManager {
func handleRemoteNotification(_ notification: [String: AnyObject]) {

if FeatureFlags.remoteOverridesEnabled {

if let expirationStr = notification["expiration"] as? String {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
if let expiration = formatter.date(from: expirationStr) {
guard expiration > Date() else {
log.error("Expired notification: %{public}@", String(describing: notification))
return
}
} else {
log.error("Invalid expiration: %{public}@", expirationStr)
return
}
}

if let command = RemoteCommand(notification: notification, allowedPresets: loopManager.settings.overridePresets) {
switch command {
case .temporaryScheduleOverride(let override):
Expand Down Expand Up @@ -1272,10 +1287,10 @@ extension DeviceDataManager {
}
}
}
// Wait up to 25 seconds for uploads to finish
// Wait up to 25 seconds for uploads triggered by these commands to finish
let _ = remoteDataServicesManager.waitForUploadsToFinish(timeout: .now() + TimeInterval(25))
} else {
log.info("Unhandled remote notification: %{public}@", String(describing: notification))
log.error("Unhandled remote notification: %{public}@", String(describing: notification))
}
}
log.info("Finished handling remote notification")
Expand Down