MCPcopy
hub / github.com/msgbyte/tianji / recordServerStatus

Function recordServerStatus

src/server/model/serverStatus.ts:97–152  ·  view source on GitHub ↗
(
  info: ServerStatusInfo,
  requestContext: ServerStatusRequestContext = {}
)

Source from the content-addressed store, hash-verified

95});
96
97export async function recordServerStatus(
98 info: ServerStatusInfo,
99 requestContext: ServerStatusRequestContext = {}
100) {
101 const { workspaceId, name, hostname, timeout, payload } = info;
102
103 if (!workspaceId || !name || !hostname) {
104 console.warn(
105 '[ServerStatus] lost some necessary params, request will be ignore',
106 info
107 );
108 return;
109 }
110
111 // Get current server map from cache
112 const serverMap = await getServerMapFromCache(workspaceId);
113
114 // Update current server status
115 const serverKey = name || hostname;
116 serverMap[serverKey] = {
117 workspaceId,
118 name,
119 hostname,
120 timeout,
121 updatedAt: Date.now(),
122 payload: {
123 ...requestContext,
124 ...payload,
125 },
126 };
127
128 // Save updated server map to cache
129 await saveServerMapToCache(workspaceId, serverMap);
130
131 // Update server history using cache
132 const history = await getServerHistoryFromCache(workspaceId, serverKey);
133 history.push(serverMap[serverKey]);
134
135 // Keep only the last 20 records
136 if (history.length > 20) {
137 history.shift();
138 }
139
140 saveServerHistoryToCache(workspaceId, serverKey, history).catch((err) => {
141 logger.error('[ServerStatus] Error saving history to cache:', err);
142 });
143
144 promServerCounter.set(
145 {
146 workspaceId,
147 },
148 Object.keys(serverMap).length
149 );
150
151 subscribeEventBus.emit('onServerStatusUpdate', workspaceId, serverMap);
152}
153
154export async function clearOfflineServerStatus(workspaceId: string) {

Callers 2

initUdpServerFunction · 0.85
serverStatus.tsFile · 0.85

Calls 8

getServerMapFromCacheFunction · 0.85
saveServerMapToCacheFunction · 0.85
saveServerHistoryToCacheFunction · 0.85
warnMethod · 0.80
nowMethod · 0.80
catchMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected