Skip to content

Commit

Permalink
add tasks to workflow in proxy - initial
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvigneshwars committed Sep 17, 2024
1 parent 33f75ba commit 6e6bed6
Showing 1 changed file with 201 additions and 1 deletion.
202 changes: 201 additions & 1 deletion graph-proxy/src/graphql/workflows.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ArgoServerUrl;
use argo_workflows_openapi::{
APIResult, IoArgoprojWorkflowV1alpha1Workflow, IoArgoprojWorkflowV1alpha1WorkflowStatus,
APIResult, IoArgoprojWorkflowV1alpha1NodeStatus, IoArgoprojWorkflowV1alpha1Workflow,
IoArgoprojWorkflowV1alpha1WorkflowStatus,
};
use async_graphql::{Context, Object, SimpleObject, Union};
use axum_extra::headers::{authorization::Bearer, Authorization};
Expand Down Expand Up @@ -185,6 +186,205 @@ impl TryFrom<IoArgoprojWorkflowV1alpha1WorkflowStatus> for WorkflowErroredStatus
}
}

/// A Task
#[derive(Debug, SimpleObject)]
struct Task {
/// The name given to the task
name: String,
/// Status of a Task
status: WorkflowStatus,
}

impl TryFrom<IoArgoprojWorkflowV1alpha1Workflow> for Task {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1Workflow) -> Result<Self, Self::Error> {
Ok(Self {
name: value.metadata.name.unwrap(),
status: value.status.unwrap().try_into()?,
})
}
}

/// The status of a workflow
#[derive(Debug, Union)]
#[allow(clippy::missing_docs_in_private_items)]
enum TaskStatus {
Pending(TaskPendingStatus),
Running(TaskRunningStatus),
Succeeded(TaskSucceededStatus),
Failed(TaskFailedStatus),
Errored(TaskErroredStatus),
Skipped(TaskSkippedStatus),
Omitted(TaskOmittedStatus),
}

impl TryFrom<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskStatus {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Result<Self, Self::Error> {
match value.phase.as_deref() {
Some("Pending") => Ok(Self::Pending(TaskPendingStatus::from(value))),
Some("Running") => Ok(Self::Running(TaskRunningStatus::try_from(value)?)),
Some("Succeeded") => Ok(Self::Succeeded(TaskSucceededStatus::try_from(value)?)),
Some("Failed") => Ok(Self::Failed(TaskFailedStatus::try_from(value)?)),
Some("Error") => Ok(Self::Errored(TaskErroredStatus::try_from(value)?)),
Some("Skipped") => Ok(Self::Skipped(TaskSkippedStatus::from(value))),
Some("Omitted") => Ok(Self::Omitted(TaskOmittedStatus::from(value))),
Some(_) => Err(WorkflowParsingError::UnrecognisedPhase),
None => Err(WorkflowParsingError::UnrecognisedPhase),
}
}
}

/// Task not scheduled
#[derive(Debug, SimpleObject)]
struct TaskPendingStatus {
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl From<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskPendingStatus {
fn from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Self {
Self {
message: value.message,
}
}
}

/// Task Running
#[derive(Debug, SimpleObject)]
struct TaskRunningStatus {
/// Time at which this task started
start_time: DateTime<Utc>,
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl TryFrom<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskRunningStatus {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Result<Self, Self::Error> {
Ok(Self {
start_time: *value
.started_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
message: value.message,
})
}
}

/// Task Succeeded
#[derive(Debug, SimpleObject)]
struct TaskSucceededStatus {
/// Time at which this task started
start_time: DateTime<Utc>,
/// Time at which this tasj started
end_time: DateTime<Utc>,
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl TryFrom<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskSucceededStatus {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Result<Self, Self::Error> {
Ok(Self {
start_time: *value
.started_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
end_time: *value
.finished_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
message: value.message,
})
}
}

/// Task Skipped
#[derive(Debug, SimpleObject)]
struct TaskSkippedStatus {
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl From<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskSkippedStatus {
fn from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Self {
Self {
message: value.message,
}
}
}

/// Task Failed
#[derive(Debug, SimpleObject)]
struct TaskFailedStatus {
/// Time at which this workflow started
start_time: DateTime<Utc>,
/// Time at which this workflow completed
end_time: DateTime<Utc>,
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl TryFrom<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskFailedStatus {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Result<Self, Self::Error> {
Ok(Self {
start_time: *value
.started_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
end_time: *value
.finished_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
message: value.message,
})
}
}

/// Task Errored
#[derive(Debug, SimpleObject)]
struct TaskErroredStatus {
/// Time at which this workflow started
start_time: DateTime<Utc>,
/// Time at which this workflow completed
end_time: DateTime<Utc>,
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl TryFrom<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskErroredStatus {
type Error = WorkflowParsingError;

fn try_from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Result<Self, Self::Error> {
Ok(Self {
start_time: *value
.started_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
end_time: *value
.finished_at
.ok_or(WorkflowParsingError::MissingStartTime)?,
message: value.message,
})
}
}

/// Task omitted
#[derive(Debug, SimpleObject)]
struct TaskOmittedStatus {
/// A human readable message indicating details about why the task is in this condition
message: Option<String>,
}

impl From<IoArgoprojWorkflowV1alpha1NodeStatus> for TaskOmittedStatus {
fn from(value: IoArgoprojWorkflowV1alpha1NodeStatus) -> Self {
Self {
message: value.message,
}
}
}

/// Queries related to [`Workflow`]s
#[derive(Debug, Clone, Default)]
pub struct WorkflowsQuery;
Expand Down

0 comments on commit 6e6bed6

Please sign in to comment.