Update to 15 mins`
This commit is contained in:
parent
4173163963
commit
c4eab94ba9
13
.woodpecker.yaml
Normal file
13
.woodpecker.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
steps:
|
||||||
|
build-and-push:
|
||||||
|
when:
|
||||||
|
event: [push]
|
||||||
|
branch: [main]
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: elisha852/omegabasms
|
||||||
|
tags: latest
|
||||||
|
username:
|
||||||
|
from_secret: DOCKER_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: DOCKER_PASSWORD
|
||||||
28
index.js
28
index.js
@ -267,7 +267,7 @@ async function startClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
function renderDashboard() {
|
function renderDashboard(clientState) {
|
||||||
const uptime = Math.floor((Date.now() - startTime) / 1000);
|
const uptime = Math.floor((Date.now() - startTime) / 1000);
|
||||||
const h = Math.floor(uptime / 3600);
|
const h = Math.floor(uptime / 3600);
|
||||||
const m = Math.floor((uptime % 3600) / 60);
|
const m = Math.floor((uptime % 3600) / 60);
|
||||||
@ -286,7 +286,7 @@ function renderDashboard() {
|
|||||||
`<tr><td>${name}</td><td>${count}</td></tr>`
|
`<tr><td>${name}</td><td>${count}</td></tr>`
|
||||||
).join('');
|
).join('');
|
||||||
|
|
||||||
const connected = client && !restarting;
|
const connected = clientState === 'CONNECTED';
|
||||||
|
|
||||||
const api = JSON.stringify({
|
const api = JSON.stringify({
|
||||||
uptime, uptimeStr, connected,
|
uptime, uptimeStr, connected,
|
||||||
@ -376,13 +376,29 @@ poll();
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
async function getClientState() {
|
||||||
|
if (!client || restarting) return 'DISCONNECTED';
|
||||||
|
try {
|
||||||
|
return await client.getState();
|
||||||
|
} catch {
|
||||||
|
return 'DISCONNECTED';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = http.createServer(async (req, res) => {
|
||||||
if (req.url === '/liveness') {
|
if (req.url === '/liveness') {
|
||||||
|
const state = await getClientState();
|
||||||
|
if (state === 'CONNECTED') {
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
res.end('OK');
|
res.end('OK');
|
||||||
|
} else {
|
||||||
|
res.writeHead(503, { 'Content-Type': 'text/plain' });
|
||||||
|
res.end('NOT_CONNECTED');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req.url === '/api/stats') {
|
if (req.url === '/api/stats') {
|
||||||
|
const clientState = await getClientState();
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
uptime: Math.floor((Date.now() - startTime) / 1000),
|
uptime: Math.floor((Date.now() - startTime) / 1000),
|
||||||
@ -390,7 +406,8 @@ const server = http.createServer((req, res) => {
|
|||||||
const t = Math.floor((Date.now() - startTime) / 1000);
|
const t = Math.floor((Date.now() - startTime) / 1000);
|
||||||
return Math.floor(t/3600)+'h '+Math.floor((t%3600)/60)+'m '+t%60+'s';
|
return Math.floor(t/3600)+'h '+Math.floor((t%3600)/60)+'m '+t%60+'s';
|
||||||
})(),
|
})(),
|
||||||
connected: !!(client && !restarting),
|
connected: clientState === 'CONNECTED',
|
||||||
|
clientState,
|
||||||
totalForwarded,
|
totalForwarded,
|
||||||
queued: messageQueue.length,
|
queued: messageQueue.length,
|
||||||
flushTime: flushTime(),
|
flushTime: flushTime(),
|
||||||
@ -399,8 +416,9 @@ const server = http.createServer((req, res) => {
|
|||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const clientState = await getClientState();
|
||||||
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
||||||
res.end(renderDashboard());
|
res.end(renderDashboard(clientState));
|
||||||
});
|
});
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
server.listen(PORT, () => log('INIT', `Dashboard on http://0.0.0.0:${PORT}`));
|
server.listen(PORT, () => log('INIT', `Dashboard on http://0.0.0.0:${PORT}`));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user