Basic cluster functionality

Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
2022-07-11 14:21:57 +02:00
parent aace2dd2de
commit b626f23792
5 changed files with 110 additions and 31 deletions

View File

@ -9,7 +9,7 @@ const { default: resolve } = require('@rollup/plugin-node-resolve');
const svelte = require('rollup-plugin-svelte');
const { terser } = require('rollup-plugin-terser');
async function build(server) {
async function build({ server, settings }) {
const serverDomain = server.settings.domain || 'localhost';
const serverPort = server.settings.port || 80;
const serverBase = `${serverDomain}:${serverPort}`;
@ -49,6 +49,7 @@ async function build(server) {
preventAssignment: false,
values: {
'__SERVER__': serverBase,
'__CLUSTERS__': JSON.stringify(settings.clusters),
},
}),
],
@ -62,6 +63,7 @@ async function build(server) {
});
return {
map: output[0].map.toUrl(),
code: output[0].code,
css: cssOutput.css,
};

View File

@ -10,10 +10,15 @@ async function createDashboardSocket(server) {
route: '/statusdashboard/socket',
onOpen: async ws => {
function sendTime() {
ws.send(JSON.stringify({
cmd: 'time',
time: new Date().getTime(),
}));
try {
ws.send(JSON.stringify({
cmd: 'time',
time: new Date().getTime(),
}));
}
catch {
return;
}
}
sendTime();
@ -36,13 +41,19 @@ async function createDashboardSocket(server) {
mappedServices[s.id] = {
name: s.name,
lastBeat: lastBeat || {},
cluster: s.cluster,
};
}
ws.send(JSON.stringify({
cmd: 'data',
data: mappedServices,
}));
try {
ws.send(JSON.stringify({
cmd: 'data',
data: mappedServices,
}));
}
catch {
return;
}
}
sendStatuses();
@ -51,7 +62,6 @@ async function createDashboardSocket(server) {
onUpgrade: async () => ({ id: makeId(10) }),
onMessage: async (ws, msg) => {
msg = JSON.parse(decoder.decode(msg));
console.log('msg', msg);
if (!msg || !msg.command) {
return;