Fix: strict 15m online threshold for agents

This commit is contained in:
ypratama committed 2026-09-04 16:35:42 +07:00
1 parent 64f77187d8
commit f0d9a55a56
1 file changed
+15 -14
+15 -14
View File
@@ -112,8 +112,6 @@ export async function fetchAgentsFromMongo(
),
]);
const isOnline = !!activeFlow;
const registryLastSeenRaw = item.last_seen_at;
let lastSeenDate: Date | null = null;
if (registryLastSeenRaw?.date) {
@@ -137,19 +135,22 @@ export async function fetchAgentsFromMongo(
}
}
const fifteenMinutesAgo = new Date(Date.now() - 15 * 60000);
const isOnline = lastSeenDate ? lastSeenDate >= fifteenMinutesAgo : !!activeFlow;
let statusHuman = 'No Flows Detected';
if (isOnline) {
if (lastSeenDate) {
const now = new Date();
const isToday = lastSeenDate.getDate() === now.getDate() &&
lastSeenDate.getMonth() === now.getMonth() &&
lastSeenDate.getFullYear() === now.getFullYear();
const timeStr = lastSeenDate.toLocaleTimeString('id-ID', { timeZone: 'Asia/Jakarta', hour: '2-digit', minute: '2-digit' }) + ' WIB';
const dateStr = lastSeenDate.toLocaleDateString('id-ID', { timeZone: 'Asia/Jakarta', day: '2-digit', month: '2-digit' });
statusHuman = isToday ? `Last seen: ${timeStr}` : `Last seen: ${dateStr} ${timeStr}`;
} else {
statusHuman = 'Last seen: Just now';
}
if (lastSeenDate) {
const now = new Date();
const isToday = lastSeenDate.getDate() === now.getDate() &&
lastSeenDate.getMonth() === now.getMonth() &&
lastSeenDate.getFullYear() === now.getFullYear();
const timeStr = lastSeenDate.toLocaleTimeString('id-ID', { timeZone: 'Asia/Jakarta', hour: '2-digit', minute: '2-digit' }) + ' WIB';
const dateStr = lastSeenDate.toLocaleDateString('id-ID', { timeZone: 'Asia/Jakarta', day: '2-digit', month: '2-digit' });
const seenStr = isToday ? timeStr : `${dateStr} ${timeStr}`;
statusHuman = isOnline ? `Last seen: ${seenStr}` : `Offline (Last seen: ${seenStr})`;
} else if (isOnline) {
statusHuman = 'Last seen: Just now';
}
return {