Skip to content

Commit

Permalink
revise: add the ord feature
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Sep 23, 2024
1 parent c822006 commit 9813cbc
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changes the `v1::types::responses::service` module to
`v1::types::responses::service_info`.
- Makes `v1::types::task::State` `Copy`.
- Adds the `ord` feature for all types.

## 0.2.0 - 08-08-2024

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
[features]
default = ["types"]
client = ["dep:anyhow", "types", "dep:serde_json", "dep:url"]
ord = []
serde = ["dep:serde", "dep:serde_json"]
types = ["dep:url"]

Expand Down
1 change: 1 addition & 0 deletions src/v1/client/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub enum View {
/// Only includes the `id` and `state` fields in the returned task.
#[default]
Expand Down
2 changes: 2 additions & 0 deletions src/v1/types/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use service_info::ServiceInfo;
/// A response from `POST /tasks`.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct CreateTask {
/// The ID of the created task.
pub id: String,
Expand All @@ -16,6 +17,7 @@ pub struct CreateTask {
/// The response from `GET /tasks`.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct ListTasks<Task> {
/// The tasks in this page of results.
pub tasks: Vec<Task>,
Expand Down
6 changes: 6 additions & 0 deletions src/v1/types/responses/service_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub const TES_VERSION: &str = "1.1.0";
/// only be `"tes"` but it's still technically listed as an enum.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub enum Artifact {
/// A task execution service.
#[cfg_attr(feature = "serde", serde(rename = "tes"))]
Expand All @@ -27,6 +28,7 @@ pub enum Artifact {
/// An organization provided a TES service.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Organization {
/// The organization name.
pub name: String,
Expand All @@ -38,6 +40,7 @@ pub struct Organization {
/// A type of service.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct ServiceType {
/// Namespace in reverse domain name format.
pub group: String,
Expand All @@ -53,6 +56,7 @@ pub struct ServiceType {
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct ServiceInfo {
/// A unique identifier for the service.
id: String,
Expand Down Expand Up @@ -157,8 +161,10 @@ impl ServiceInfo {

#[cfg(test)]
mod tests {
#[cfg(feature = "serde")]
use pretty_assertions::assert_eq;

#[cfg(feature = "serde")]
use super::*;

#[cfg(feature = "serde")]
Expand Down
2 changes: 2 additions & 0 deletions src/v1/types/responses/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::v1::types::task::State;
/// A response for when `?view=MINIMAL` in a task endpoint.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct MinimalTask {
/// The ID.
pub id: String,
Expand All @@ -18,6 +19,7 @@ pub struct MinimalTask {
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub enum Response {
/// A response for when `?view=MINIMAL` in a task endpoint.
Minimal(MinimalTask),
Expand Down
14 changes: 14 additions & 0 deletions src/v1/types/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Tasks submitted to a service.
#[cfg(feature = "ord")]
use std::collections::BTreeMap;
#[cfg(not(feature = "ord"))]
use std::collections::HashMap;

use chrono::DateTime;
Expand All @@ -15,6 +18,7 @@ pub use executor::Executor;
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub enum State {
/// An unknown state.
#[default]
Expand Down Expand Up @@ -60,6 +64,7 @@ impl State {
/// An input for a TES task.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Input {
/// An optional name.
pub name: Option<String>,
Expand All @@ -84,6 +89,7 @@ pub struct Input {
/// An output for a TES task.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Output {
/// An optional name.
pub name: Option<String>,
Expand All @@ -105,6 +111,7 @@ pub struct Output {
/// Requested resources for a TES task.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Resources {
/// The number of CPU cores.
pub cpu_cores: Option<i64>,
Expand All @@ -125,6 +132,7 @@ pub struct Resources {
/// An output file log.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct OutputFileLog {
/// The URL.
pub url: String,
Expand All @@ -139,6 +147,7 @@ pub struct OutputFileLog {
/// A task log.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct TaskLog {
/// The executor logs.
pub logs: Vec<executor::Log>,
Expand All @@ -159,6 +168,7 @@ pub struct TaskLog {
/// A task.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Task {
/// The ID.
pub id: Option<String>,
Expand Down Expand Up @@ -188,7 +198,11 @@ pub struct Task {
pub volumes: Option<Vec<String>>,

/// The tags.
#[cfg(not(feature = "ord"))]
pub tags: Option<HashMap<String, String>>,
/// The tags.
#[cfg(feature = "ord")]
pub tags: Option<BTreeMap<String, String>>,

/// The logs.
pub logs: Option<Vec<TaskLog>>,
Expand Down
9 changes: 9 additions & 0 deletions src/v1/types/task/executor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Executor declared within tasks.
#[cfg(feature = "ord")]
use std::collections::BTreeMap;
#[cfg(not(feature = "ord"))]
use std::collections::HashMap;

use chrono::DateTime;
Expand All @@ -12,6 +15,7 @@ use chrono::Utc;
/// the task.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Executor {
/// The image.
pub image: String,
Expand All @@ -32,12 +36,17 @@ pub struct Executor {
pub stderr: Option<String>,

/// The environment variables.
#[cfg(not(feature = "ord"))]
pub env: Option<HashMap<String, String>>,
/// The environment variables.
#[cfg(feature = "ord")]
pub env: Option<BTreeMap<String, String>>,
}

/// A log for an [`Executor`].
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub struct Log {
/// The start time.
pub start_time: Option<DateTime<Utc>>,
Expand Down
1 change: 1 addition & 0 deletions src/v1/types/task/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// A type of file.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ord", derive(Ord, PartialOrd))]
pub enum Type {
/// A file.
#[cfg_attr(feature = "serde", serde(rename = "FILE"))]
Expand Down

0 comments on commit 9813cbc

Please sign in to comment.