From c4eab94ba933d196fd40ca411f44028942fa0e7c Mon Sep 17 00:00:00 2001 From: elishadavidi <62501723+elishadavidi@users.noreply.github.com> Date: Thu, 28 May 2026 20:26:32 +0300 Subject: [PATCH] Update to 15 mins` --- .woodpecker.yaml | 13 +++++++++++++ index.js | 32 +++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 .woodpecker.yaml diff --git a/.woodpecker.yaml b/.woodpecker.yaml new file mode 100644 index 0000000..d06351b --- /dev/null +++ b/.woodpecker.yaml @@ -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 diff --git a/index.js b/index.js index aab096f..3c58db0 100644 --- a/index.js +++ b/index.js @@ -267,7 +267,7 @@ async function startClient() { } const http = require('http'); -function renderDashboard() { +function renderDashboard(clientState) { const uptime = Math.floor((Date.now() - startTime) / 1000); const h = Math.floor(uptime / 3600); const m = Math.floor((uptime % 3600) / 60); @@ -286,7 +286,7 @@ function renderDashboard() { `${name}${count}` ).join(''); - const connected = client && !restarting; + const connected = clientState === 'CONNECTED'; const api = JSON.stringify({ uptime, uptimeStr, connected, @@ -376,13 +376,29 @@ poll(); `; } -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') { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('OK'); + const state = await getClientState(); + if (state === 'CONNECTED') { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('OK'); + } else { + res.writeHead(503, { 'Content-Type': 'text/plain' }); + res.end('NOT_CONNECTED'); + } return; } if (req.url === '/api/stats') { + const clientState = await getClientState(); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ 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); return Math.floor(t/3600)+'h '+Math.floor((t%3600)/60)+'m '+t%60+'s'; })(), - connected: !!(client && !restarting), + connected: clientState === 'CONNECTED', + clientState, totalForwarded, queued: messageQueue.length, flushTime: flushTime(), @@ -399,8 +416,9 @@ const server = http.createServer((req, res) => { })); return; } + const clientState = await getClientState(); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); - res.end(renderDashboard()); + res.end(renderDashboard(clientState)); }); const PORT = process.env.PORT || 3000; server.listen(PORT, () => log('INIT', `Dashboard on http://0.0.0.0:${PORT}`));