mirror of
https://github.com/tale/headplane.git
synced 2026-08-27 15:37:04 +00:00
feat: switch agent fetching to the server side
this brings the benefit of fitting in the revalidator lifecycle we have created via the useLiveData hook.
This commit is contained in:
+11
-5
@@ -74,11 +74,17 @@ export default await createHonoServer({
|
||||
return appLoadContext;
|
||||
},
|
||||
|
||||
configure(server, { upgradeWebSocket }) {
|
||||
if (appLoadContext.agents !== undefined) {
|
||||
// We need this since we cannot pass the WSEvents context
|
||||
(upgradeWebSocket as UpgradeWebSocket<WebSocket>)(
|
||||
appLoadContext.agents.configureSocket,
|
||||
configure(app, { upgradeWebSocket }) {
|
||||
const agentManager = appLoadContext.agents;
|
||||
if (agentManager) {
|
||||
app.get(
|
||||
`${__PREFIX__}/_dial`,
|
||||
// We need this since we cannot pass the WSEvents context
|
||||
// Also important to not pass the callback directly
|
||||
// since we need to retain `this` context
|
||||
(upgradeWebSocket as UpgradeWebSocket<WebSocket>)((c) =>
|
||||
agentManager.configureSocket(c),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
+11
-1
@@ -49,10 +49,20 @@ class AgentManager {
|
||||
return Array.from(this.agents.keys());
|
||||
}
|
||||
|
||||
lookup(nodeIds: string[]) {
|
||||
const entries = this.cache.toJSON();
|
||||
const missing = nodeIds.filter((nodeId) => !entries[nodeId]);
|
||||
if (missing.length > 0) {
|
||||
this.requestData(missing);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
// Request data from all connected agents
|
||||
// This does not return anything, but caches the data which then needs to be
|
||||
// queried by the caller separately.
|
||||
requestData(nodeList: string[]) {
|
||||
private requestData(nodeList: string[]) {
|
||||
const NodeIDs = [...new Set(nodeList)];
|
||||
NodeIDs.map((node) => {
|
||||
log.debug('agent', 'Requesting agent data for %s', node);
|
||||
|
||||
Reference in New Issue
Block a user