Skip to content

Commit

Permalink
feat: compute and display status of pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 16, 2024
1 parent f9d2a94 commit ccd25c9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
9 changes: 8 additions & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ Job status:
1. created: can be assigned to worker
2. assigned: assigned to worker
3. error: unexpected error
4. finished: finished, successful or failed
4. finished: finished, successful(build_success && pushpkg_success) or failed

Pipeline status is computed from job status, ordered by precedence:

1. error: any job has status `error`
2. failed: any job has status `finished` and either `build_success` or `pushpkg_success` is false
3. success: all job has status `finished`, `build_success` and `pushpkg_success` are true
4. running: otherwise

## Authentication

Expand Down
43 changes: 43 additions & 0 deletions frontend/src/pages/pipelines/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,48 @@
item-value="id"
@update:options="loadItems">
<template #item.status="{ item }">
<div style="margin-top: 5px"></div>
<v-chip
color="green"
variant="flat"
density="comfortable"
v-if="(item as Job).status === 'success'"
prepend-icon="mdi:mdi-check-circle"
:to="{ path: `/pipelines/${(item as Pipeline).id}` }"
>
Passed
</v-chip>
<v-chip
color="red"
variant="flat"
density="comfortable"
v-else-if="(item as Job).status === 'failed'"
prepend-icon="mdi:mdi-close-circle"
:to="{ path: `/pipelines/${(item as Pipeline).id}` }"
>
Failed
</v-chip>
<v-chip
color="grey"
variant="flat"
density="comfortable"
v-else-if="(item as Job).status === 'running'"
prepend-icon="mdi:mdi-progress-question"
:to="{ path: `/pipelines/${(item as Pipeline).id}` }"
>
Running
</v-chip>
<v-chip
color="red"
variant="flat"
density="comfortable"
v-else-if="(item as Job).status === 'error'"
prepend-icon="mdi:mdi-alert-circle"
:to="{ path: `/pipelines/${(item as Pipeline).id}` }"
>
Error
</v-chip>

<div class="d-flex align-center">
<v-icon size="x-small" style="margin-right: 5px;">mdi:mdi-calendar</v-icon>
<div>
Expand Down Expand Up @@ -138,6 +180,7 @@
archs: string;
creator_github_login: string;
creator_github_avatar_url: string;
status: string;
jobs: Job[];
}
Expand Down
39 changes: 39 additions & 0 deletions server/src/routes/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use diesel::{
SelectableHelper,
};
use serde::{Deserialize, Serialize};
use tracing::error;

#[derive(Deserialize)]
pub struct PipelineNewRequest {
Expand Down Expand Up @@ -149,6 +150,7 @@ pub struct PipelineListResponseItem {
github_pr: Option<i64>,
packages: String,
archs: String,
status: &'static str,

// from pipeline creator
creator_github_login: Option<String>,
Expand Down Expand Up @@ -205,6 +207,42 @@ pub async fn pipeline_list(
.zip(pipelines)
.zip(users)
{
let mut has_error = false;
let mut has_failed = false;
let mut has_unfinished = true;
for job in &jobs {
match (job.status.as_str(), job.build_success, job.pushpkg_success) {
("error", _, _) => has_error = true,
("finished", Some(true), Some(true)) => {
// success
}
("finished", _, _) => {
// failed
has_failed = true;
}
("created", _, _) => {
has_unfinished = true;
}
("assigned", _, _) => {
has_unfinished = true;
}
_ => {
error!("Got job with unknown status: {:?}", job);
}
}
}

let status = if has_error {
"error"
} else if has_failed {
"failed"
} else if has_unfinished {
"running"
} else {
"success"
};

// compute pipeline status based on job status
items.push(PipelineListResponseItem {
id: pipeline.id,
git_branch: pipeline.git_branch,
Expand All @@ -213,6 +251,7 @@ pub async fn pipeline_list(
archs: pipeline.archs,
creation_time: pipeline.creation_time,
github_pr: pipeline.github_pr,
status,

creator_github_login: creator
.as_ref()
Expand Down

0 comments on commit ccd25c9

Please sign in to comment.