1- <script setup lang="ts">
2- import {ref , Ref } from " vue" ;
1+ <script setup lang="tsx">
2+ import {h , ref , Ref } from " vue" ;
3+ import {parseISO , differenceInHours } from " date-fns" ;
34import {formatISODate } from " ../../utils/formatting" ;
45import {CollectorConfig , BenchmarkJobStatus } from " ./data" ;
56
67const props = defineProps <{
78 collector: CollectorConfig ;
89}>();
910
10- function statusClass(c : CollectorConfig ): string {
11- return c .isActive ? " active" : " inactive" ;
12- }
13-
1411const FILTERS: BenchmarkJobStatus [] = [
1512 " InProgress" ,
1613 " Queued" ,
@@ -40,6 +37,37 @@ function formatJobStatus(status: BenchmarkJobStatus): string {
4037 return " Unknown" ;
4138 }
4239}
40+
41+ function ActiveStatus({collector }: {collector: CollectorConfig }) {
42+ const now = new Date ();
43+ const maxInactivityHours = 1 ;
44+ const lastHeartBeatAt = parseISO (collector .lastHeartbeatAt );
45+ const hourDiff = differenceInHours (now , lastHeartBeatAt );
46+ let statusText = " Active" ;
47+ let statusClass = " active" ;
48+
49+ switch (collector .isActive ) {
50+ case false :
51+ if (hourDiff >= maxInactivityHours ) {
52+ statusText = " Offline" ;
53+ statusClass = " offline" ;
54+ } else {
55+ statusText = " Active" ;
56+ statusClass = " active" ;
57+ }
58+ break ;
59+ case true :
60+ statusText = " Inactive" ;
61+ statusClass = " inactive" ;
62+ break ;
63+ }
64+
65+ return (
66+ <span class = { ` collector-sm-padding-left-right status ${statusClass } ` } >
67+ { statusText }
68+ </span >
69+ );
70+ }
4371 </script >
4472
4573<template >
@@ -54,12 +82,7 @@ function formatJobStatus(status: BenchmarkJobStatus): string {
5482 class =" collector-sm-padding-left-right collector-left-divider"
5583 >{{ collector.target }}</span
5684 >
57- <span
58- class =" collector-sm-padding-left-right status"
59- :class =" statusClass(collector)"
60- >
61- {{ collector.isActive ? "Active" : "Inactive" }}
62- </span >
85+ <ActiveStatus :collector =" collector" />
6386 </span >
6487 </div >
6588 </div >
@@ -235,6 +258,11 @@ $sm-radius: 8px;
235258 font-weight : bold ;
236259}
237260.status.inactive {
261+ background : #ccc ;
262+ color : white ;
263+ font-weight : bold ;
264+ }
265+ .status.offline {
238266 background : red ;
239267 color : white ;
240268 font-weight : bold ;
0 commit comments