-
Notifications
You must be signed in to change notification settings - Fork 1
feat: improve polling server task status #45
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,9 +200,31 @@ extension SleepTab { | |
| self.status = .progress("Uploading Encrypted Data…") | ||
| let taskID = try await uploadSample(data, uid: uid) | ||
|
|
||
| self.status = .progress("Analyzing sleep quality…") | ||
| self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date) | ||
| self.status = nil | ||
| self.status = .progress("Task submitted to server…") | ||
| var lastStatus: String? | ||
|
|
||
| while true { | ||
| let statusResponse = try await Network.shared.getStatus(for: serverTask, id: taskID, uid: uid) | ||
|
|
||
| if statusResponse.status != lastStatus { | ||
| lastStatus = statusResponse.status | ||
| switch statusResponse.status { | ||
| case "started": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just in case, add 'active' |
||
| self.status = .progress("Analyzing sleep quality…") | ||
| case "reserved", "queued": | ||
| self.status = .progress("Task is in queue") | ||
| case "pending", "failure", "revoked", "unknown", "error": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our design, we added the cancel_task endpoint, which returns the status revoked. |
||
| throw TaskError.needToRetry | ||
| case "completed", "success": | ||
| self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date) | ||
| self.status = nil | ||
| break | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it exit the 'switch' or the 'while' loop ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i m not familiar with swift, maybe 'return' is more suited |
||
| default: break | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you should throw an error if we don't know the status of: default: |
||
| } | ||
| } | ||
|
|
||
| try await Task.sleep(for: .seconds(statusResponse.status == "queued" || statusResponse.status == "started" ? 5 : 10)) | ||
| } | ||
| } catch { | ||
| self.status = .error(error.localizedDescription) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do you exit this while true loop ?