-
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?
Conversation
| var lastStatus: String? | ||
|
|
||
| while true { | ||
| let statusResponse = try await Network.shared.getStatus(for: serverTask, id: taskID, uid: uid) |
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 ?
| self.status = .progress("Analyzing sleep quality…") | ||
| case "reserved", "queued": | ||
| self.status = .progress("Task is in queue") | ||
| case "pending", "failure", "revoked", "unknown", "error": |
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.
In our design, we added the cancel_task endpoint, which returns the status revoked.
it's a manual cancellation initiated by the user and should not be considered an error.
| if statusResponse.status != lastStatus { | ||
| lastStatus = statusResponse.status | ||
| switch statusResponse.status { | ||
| case "started": |
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.
just in case, add 'active'
| case "completed", "success": | ||
| self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date) | ||
| self.status = nil | ||
| break |
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.
does it exit the 'switch' or the 'while' loop ?
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.
i m not familiar with swift, maybe 'return' is more suited
| self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date) | ||
| self.status = nil | ||
| break | ||
| default: break |
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.
maybe you should throw an error if we don't know the status of:
default:
throw TaskError.unexpectedStatus(statusResponse.status)
Uh oh!
There was an error while loading. Please reload this page.