Fix: online threshold 15m->1h, offline selalu tampilkan tanggal+jam lengkap

This commit is contained in:
ypratama committed 2026-09-09 10:12:05 +07:00
1 parent 773e654616
commit 77708fa8e6
1 file changed
+11 -5
+11 -5
View File
@@ -89,7 +89,8 @@ export async function fetchAgentsFromMongo(
}
// 3. Optimize status check and last seen per agent using parallel indexed queries
const fifteenMinutesAgoQuery = new Date(Date.now() - 15 * 60000);
// Agent dianggap Online jika ada flow dalam 1 jam terakhir
const oneHourAgoQuery = new Date(Date.now() - 60 * 60000);
const agentResults = await Promise.all(
agentSource.map(async (item: any, idx: number) => {
@@ -99,7 +100,7 @@ export async function fetchAgentsFromMongo(
// Execute status checks for active flow, latest flow, and latest summary in parallel
const [activeFlow, latestFlow, latestSummary] = await Promise.all([
db.collection('flows').findOne(
{ agent_uuid: uuid, timestamp: { $gte: fifteenMinutesAgoQuery } },
{ agent_uuid: uuid, timestamp: { $gte: oneHourAgoQuery } },
{ projection: { _id: 1 } }
),
db.collection('flows').findOne(
@@ -145,9 +146,14 @@ export async function fetchAgentsFromMongo(
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})`;
if (isOnline) {
// Online: cukup tampilkan jam saja (hari ini pasti)
statusHuman = `Last seen: ${timeStr}`;
} else {
// Offline: selalu tampilkan tanggal + jam lengkap
statusHuman = `Offline (Last seen: ${dateStr} ${timeStr})`;
}
} else if (isOnline) {
statusHuman = 'Last seen: Just now';
}