-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
425: [BREAKING] Tasks Parity r=curquiza a=Sherlouk Closes #363 Closes #366 Closes #368 Closes #254 ## User/Client Facing * Introduces Cancel Tasks API * Introduces Delete Tasks API * Provides compiler-safe access to task types * Utilising a future-proof solution avoiding errors should new task types be added without Swift support * Provides compiler-safe access to task result details * Utilising a future-proof solution avoiding errors should new details be added without Swift support * Grouped task related models into own directory * Uses `Date` objects instead of `String` for dates within task models * Added missing fields to existing task models * Fixed error caused by global tasks * Uses compiler-safe types in task query to improve safety * Adds `total` to task results response (replacing #412) * Removed all instances of `try!` (force try) to prevent crashes in test runner ## Breaking Changes⚠️ This is a breaking change. Even with something as simple as moving to a enum for TaskType requires changes to clients. This PR looks to bring all task changes together meaning that clients can upgrade to this new and safe API design in one go. * `Task.Status` has a new value `.canceled` (handle in any `switch` cases) * `TaskType` replaces a previous String based API (use `.description` to access String) * `TasksQuery` uses compiled types instead of String APIs (example: `"indexUpdate"` is now `.indexUpdate`) * `enqueuedAt` now uses Date instead of ISO-8601 String ## Parity Reviewing documentation available on MeiliSearch's website, this PR brings the `Tasks` API up to **100% parity** with existing features. It resolves many errors caused by the previous design (both architecturally but also instability in the current release), and provides future-proofness against further scope within the tasks API. ## Personal As I am developing my own Swift based application for monitoring MeiliSearch (and it's tasks), this branch has been extremely helpful for me in exploring jobs and being able to cancel them and performing my own housekeeping. The type safety has been delightful and actually detected a bug in my original implementation which had a typo in a task name. Co-authored-by: James Sherlock <15193942+Sherlouk@users.noreply.github.com>
- Loading branch information
Showing
35 changed files
with
886 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Foundation | ||
|
||
/** | ||
`Task` instances represent the current transaction status, use the `uid` value to | ||
verify the status of your transaction. | ||
*/ | ||
public struct Task: Decodable, Equatable { | ||
/// Unique ID for the current `Task`. | ||
public let uid: Int | ||
|
||
/// Unique identifier of the targeted index | ||
public let indexUid: String? | ||
|
||
/// Returns if the task has been successful or not. | ||
public let status: Status | ||
|
||
/// Type of the task. | ||
public let type: TaskType | ||
|
||
/// Details of the task. | ||
public let details: Details? | ||
|
||
/// Duration of the task process. | ||
public let duration: String? | ||
|
||
/// Date when the task has been enqueued. | ||
public let enqueuedAt: Date | ||
|
||
/// Date when the task has been started. | ||
public let startedAt: Date? | ||
|
||
/// Date when the task has been finished, regardless of status. | ||
public let finishedAt: Date? | ||
|
||
/// ID of the the `Task` which caused this to be canceled. | ||
public let canceledBy: Int? | ||
|
||
/// Error information in case of failed update. | ||
public let error: MeiliSearch.MSErrorResponse? | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let type = try container.decode(TaskType.self, forKey: .type) | ||
|
||
self.uid = try container.decode(Int.self, forKey: .uid) | ||
self.indexUid = try container.decodeIfPresent(String.self, forKey: .indexUid) | ||
self.status = try container.decode(Status.self, forKey: .status) | ||
self.type = type | ||
self.duration = try container.decodeIfPresent(String.self, forKey: .duration) | ||
self.enqueuedAt = try container.decode(Date.self, forKey: .enqueuedAt) | ||
self.startedAt = try container.decodeIfPresent(Date.self, forKey: .startedAt) | ||
self.finishedAt = try container.decodeIfPresent(Date.self, forKey: .finishedAt) | ||
self.canceledBy = try container.decodeIfPresent(Int.self, forKey: .canceledBy) | ||
self.error = try container.decodeIfPresent(MeiliSearch.MSErrorResponse.self, forKey: .error) | ||
|
||
// we ignore errors thrown by `superDecoder` to handle cases where no details are provided by the API | ||
// for example when the type is `snapshotCreation`. | ||
let detailsDecoder = try? container.superDecoder(forKey: .details) | ||
self.details = try Details(decoder: detailsDecoder, type: type) | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case uid, indexUid, status, type, details, duration, enqueuedAt, startedAt, finishedAt, canceledBy, error | ||
} | ||
} |
Oops, something went wrong.