From 99c21c624606ae3fd2e12b70a964d1c6500e7443 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Thu, 14 Mar 2024 21:48:56 +0800 Subject: [PATCH] feat: display worker status --- frontend/src/pages/workers/index.vue | 34 +++++++++++++++++++++++++++- server/src/routes/worker.rs | 6 +++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/workers/index.vue b/frontend/src/pages/workers/index.vue index 4ef23ae..4b828c5 100644 --- a/frontend/src/pages/workers/index.vue +++ b/frontend/src/pages/workers/index.vue @@ -15,6 +15,30 @@ {{ (item as Worker).id }} + @@ -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; @@ -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, diff --git a/server/src/routes/worker.rs b/server/src/routes/worker.rs index 2763b29..1f3bfc5 100644 --- a/server/src/routes/worker.rs +++ b/server/src/routes/worker.rs @@ -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, @@ -41,6 +42,8 @@ pub struct WorkerListResponseItem { arch: String, logical_cores: i32, memory_bytes: i64, + is_live: bool, + last_heartbeat_time: DateTime, } #[derive(Serialize)] @@ -76,6 +79,7 @@ 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, @@ -83,6 +87,8 @@ pub async fn worker_list( 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, }); }