Skip to content

Commit

Permalink
feat: display worker status
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 14, 2024
1 parent 4bc562a commit 99c21c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
34 changes: 33 additions & 1 deletion frontend/src/pages/workers/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
{{ (item as Worker).id }}
</router-link>
</template>
<template #item.status="{ item }">
<v-chip
color="green"
variant="flat"
density="comfortable"
v-if="(item as Worker).is_live"
prepend-icon="mdi:mdi-check-circle"
style="margin-top: 5px; margin-bottom: 3px;"
>
Live
</v-chip>
<v-chip
color="red"
variant="flat"
density="comfortable"
v-else
prepend-icon="mdi:mdi-close-circle"
style="margin-top: 5px; margin-bottom: 3px;"
>
Dead
</v-chip>
<br/>
Last seen {{ new TimeAgo('en-US').format(new Date((item as Worker).last_heartbeat_time)) }}
</template>
</v-data-table-server>
</v-col>
</v-row>
Expand All @@ -29,6 +53,10 @@
import axios from 'axios';
import prettyBytes from 'pretty-bytes';
import { hostname } from '@/common';
import TimeAgo from 'javascript-time-ago'
import en from 'javascript-time-ago/locale/en'
TimeAgo.addDefaultLocale(en)
interface LoadItemsOpts {
page: number;
Expand All @@ -37,16 +65,20 @@
interface Worker {
id: number;
is_live: boolean;
last_heartbeat_time: string;
}
export default {
data: () => ({
itemsPerPage: 10,
itemsPerPage: 25,
headers: [
{ title: 'Worker ID', key: 'id', sortable: false },
{ title: 'Hostname', key: 'hostname', sortable: false },
{ title: 'Architecture', key: 'arch', sortable: false },
{ title: 'Logical Cores', key: 'logical_cores', sortable: false },
{ title: 'Memory Size', key: 'memory_bytes', sortable: false, value: (item: any) => prettyBytes(item.memory_bytes) },
{ title: 'Status', key: 'status', sortable: false },
],
loading: true,
totalItems: 0,
Expand Down
6 changes: 6 additions & 0 deletions server/src/routes/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use axum::extract::{Json, Query, State};
use buildit_utils::{AMD64, ARM64, LOONGSON3, MIPS64R6EL, PPC64EL, RISCV64};
use buildit_utils::{LOONGARCH64, NOARCH};

use chrono::{DateTime, Utc};
use common::{
JobOk, JobResult, WorkerHeartbeatRequest, WorkerJobUpdateRequest, WorkerPollRequest,
WorkerPollResponse,
Expand Down Expand Up @@ -41,6 +42,8 @@ pub struct WorkerListResponseItem {
arch: String,
logical_cores: i32,
memory_bytes: i64,
is_live: bool,
last_heartbeat_time: DateTime<Utc>,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -76,13 +79,16 @@ pub async fn worker_list(
};

let mut items = vec![];
let deadline = Utc::now() - chrono::Duration::try_seconds(300).unwrap();
for worker in workers {
items.push(WorkerListResponseItem {
id: worker.id,
hostname: worker.hostname,
arch: worker.arch,
logical_cores: worker.logical_cores,
memory_bytes: worker.memory_bytes,
is_live: worker.last_heartbeat_time > deadline,
last_heartbeat_time: worker.last_heartbeat_time,
});
}

Expand Down

0 comments on commit 99c21c6

Please sign in to comment.