phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
+125
-387
@@ -1,402 +1,140 @@
|
||||
<%- include('partials/header') %>
|
||||
<%- include('partials/header', { title: 'Workers', activePage: 'workers' }) %>
|
||||
<%
|
||||
const workerProcesses = Array.isArray(processes) ? processes : [];
|
||||
const onlineCount = workerProcesses.filter(p => ['online', 'running'].includes(p.status)).length;
|
||||
const workerStatusClass = status => ['online', 'running'].includes(status) ? 'status-online'
|
||||
: ['stopped', 'errored', 'offline'].includes(status) ? 'status-stopped' : 'status-pending';
|
||||
%>
|
||||
|
||||
<style>
|
||||
/* Dark theme PM2 CSS (integrates with your style.css) */
|
||||
.pm2-row { cursor: pointer; border: 1px solid #4A4A4A; }
|
||||
.pm2-row.active, .pm2-row.selected-outline {
|
||||
background-color: #555 !important;
|
||||
border-color: #8A190B !important;
|
||||
box-shadow: 0 0 0 2px rgba(138,25,11,0.4);
|
||||
}
|
||||
<section class="page-heading" aria-labelledby="workers-title">
|
||||
<div>
|
||||
<p class="eyebrow">Download operations</p>
|
||||
<h1 id="workers-title" class="page-title">Workers</h1>
|
||||
<p class="page-description">Manage your download workers and follow their output.</p>
|
||||
</div>
|
||||
<div class="page-actions">
|
||||
<span id="worker-counts" class="worker-counts"><%= onlineCount %> online · <%= workerProcesses.length %> total</span>
|
||||
<button id="refresh-list" class="button button-secondary" type="button" disabled>Refresh workers</button>
|
||||
<button id="btn-quick-add" class="button button-primary" type="button" disabled>Quick add worker</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
#logs {
|
||||
height: 60vh;
|
||||
background: #0b1220;
|
||||
color: #e6eef8;
|
||||
padding: 10px;
|
||||
font-family: monospace;
|
||||
font-size: 0.85rem;
|
||||
overflow-y: auto;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #444;
|
||||
<noscript><p class="notice">Enable JavaScript to manage workers and view live logs.</p></noscript>
|
||||
<p id="control-output" class="action-message" role="status" aria-live="polite" hidden></p>
|
||||
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.kv-label { width: 110px; display: inline-block; color: #C0C0C0; }
|
||||
.kv-value { font-weight: bold; color: #ffffff; }
|
||||
.subtle { color: #BEBEBE; font-size: 0.85rem; }
|
||||
|
||||
.badge-small { font-size: .75rem; padding: .25rem .5rem; border-radius: .4rem; }
|
||||
</style>
|
||||
|
||||
<div class="container py-3" style="max-width:1300px;">
|
||||
|
||||
<div class="row g-3">
|
||||
|
||||
<!-- LEFT COLUMN — PROCESS LIST & CONTROL CENTRE -->
|
||||
<div class="col-md-5 d-flex">
|
||||
<div class="card-dark w-100 d-flex flex-column">
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<div>
|
||||
<h4 class="mb-0">Downloader Workers</h4>
|
||||
<div class="subtle">Select a worker to manage it and view its logs.</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<button id="refresh-list" class="btn btn-sm btn-outline-light" aria-label="Refresh worker list">⟳</button>
|
||||
|
||||
<!-- NEW: ONE-CLICK CREATE -->
|
||||
<button id="btn-create" class="btn btn-sm btn-success" aria-label="Create downloader worker">
|
||||
<strong>+</strong>
|
||||
<div class="workers-layout">
|
||||
<section class="panel" aria-labelledby="worker-list-title">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<h2 id="worker-list-title">Your workers</h2>
|
||||
<p id="worker-refresh-state" class="muted" role="status" aria-live="polite">Updates every 10 seconds</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul id="process-list" class="worker-list" aria-label="Download workers">
|
||||
<% workerProcesses.forEach(p => { %>
|
||||
<li class="worker-list-item">
|
||||
<button type="button" class="worker-row" aria-pressed="false" disabled
|
||||
data-key="<%= String(p.pm_id) + ':' + p.name %>"
|
||||
data-name="<%= p.name %>" data-pmid="<%= p.pm_id %>"
|
||||
data-pid="<%= p.pid %>" data-status="<%= p.status %>"
|
||||
data-cpu="<%= p.cpu %>" data-memory="<%= p.memoryMB %>"
|
||||
data-uptime="<%= p.uptime %>" data-exec="<%= p.execPath %>">
|
||||
<span class="worker-row-heading">
|
||||
<strong class="worker-name"><%= p.name %></strong>
|
||||
<span class="badge <%= workerStatusClass(p.status) %>" data-worker-status><%= p.status %></span>
|
||||
</span>
|
||||
<span class="worker-row-meta" data-worker-metrics>CPU <%= p.cpu %> · <%= p.memoryMB %> · <%= p.uptime %></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PROCESS LIST -->
|
||||
<div id="process-list" class="list-group" style="max-height:40vh; overflow-y:auto;">
|
||||
<% if (processes && processes.length) { %>
|
||||
<% processes.forEach(p => {
|
||||
let status = (p.status || '').toLowerCase();
|
||||
let badge = 'bg-secondary';
|
||||
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||
else if (status.includes('launch') || status.includes('start')) badge = 'bg-warning text-dark';
|
||||
%>
|
||||
<a href="#"
|
||||
class="list-group-item pm2-row d-flex justify-content-between"
|
||||
data-name="<%= p.name %>"
|
||||
data-pid="<%= p.pid %>"
|
||||
data-pmid="<%= p.pm_id %>"
|
||||
data-status="<%= p.status %>"
|
||||
>
|
||||
<div>
|
||||
<strong><%= p.name %></strong>
|
||||
<span class="badge badge-small <%= badge %>"><%= p.status %></span>
|
||||
<div class="subtle"><%= p.execPath %></div>
|
||||
</div>
|
||||
|
||||
<div class="text-end">
|
||||
<div>pid: <span><%= p.pid %></span></div>
|
||||
<div class="subtle"><%= p.uptime %></div>
|
||||
</div>
|
||||
</a>
|
||||
<% }) %>
|
||||
<% } else { %>
|
||||
<div class="alert alert-warning">No downloader workers found.</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<pre id="control-output" class="mt-3 p-2" role="status" aria-live="polite" style="background:#0b0b0b; max-height:110px; overflow:auto; border-radius:6px; white-space:pre-wrap;">Worker action results will appear here.</pre>
|
||||
|
||||
<!-- CONTROL CENTRE -->
|
||||
<div id="control-centre" class="mt-3 p-3" style="display:none; background:#3A3A3A; border-radius:8px; border:1px solid #555;">
|
||||
<h5 id="cc-name">Process Name</h5>
|
||||
<div id="cc-sub" class="subtle mb-2">pm_id / pid / status</div>
|
||||
|
||||
<!-- Quick actions -->
|
||||
<div class="d-flex flex-wrap gap-2 mb-3">
|
||||
<button id="btn-start" class="btn btn-success btn-sm">Start</button>
|
||||
<button id="btn-stop" class="btn btn-danger btn-sm">Stop</button>
|
||||
<button id="btn-restart" class="btn btn-warning btn-sm">Restart</button>
|
||||
<button id="btn-delete" class="btn btn-outline-light btn-sm">Delete</button>
|
||||
</div>
|
||||
|
||||
<!-- Details -->
|
||||
<div class="small">
|
||||
<div><span class="kv-label">PM2 name</span> <span class="kv-value" id="detail-name">—</span></div>
|
||||
<div><span class="kv-label">PM2 id</span> <span class="kv-value" id="detail-pmid">—</span></div>
|
||||
<div><span class="kv-label">PID</span> <span class="kv-value" id="detail-pid">—</span></div>
|
||||
<div><span class="kv-label">Status</span> <span class="kv-value" id="detail-status">—</span></div>
|
||||
<div><span class="kv-label">Uptime</span> <span class="kv-value" id="detail-uptime">—</span></div>
|
||||
<div><span class="kv-label">CPU</span> <span class="kv-value" id="detail-cpu">—</span></div>
|
||||
<div><span class="kv-label">Memory</span> <span class="kv-value" id="detail-mem">—</span></div>
|
||||
<div><span class="kv-label">Exec Path</span> <span class="kv-value" id="detail-exec">—</span></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<div id="workers-empty" class="empty-state" <%= workerProcesses.length ? 'hidden' : '' %>>
|
||||
<h3>No workers yet</h3>
|
||||
<p>Use Quick add worker to start processing the queue.</p>
|
||||
</div>
|
||||
|
||||
<p class="field-hint worker-quick-add-hint">Quick add starts a worker immediately, named proxer-worker-1, proxer-worker-2 and so on. The next number is chosen automatically.</p>
|
||||
<details class="worker-create">
|
||||
<summary>Choose a custom name</summary>
|
||||
<form id="create-worker-form" novalidate>
|
||||
<div class="field">
|
||||
<label class="field-label" for="worker-name">Worker name</label>
|
||||
<input class="field-input" id="worker-name" name="workerName" type="text"
|
||||
required maxlength="64" pattern="[A-Za-z0-9][A-Za-z0-9_\-]{0,63}"
|
||||
autocomplete="off" spellcheck="false" placeholder="my-worker"
|
||||
aria-describedby="worker-name-hint">
|
||||
<p id="worker-name-hint" class="field-hint">Start with a letter or number. Use letters, numbers, underscores or hyphens.</p>
|
||||
</div>
|
||||
<button id="btn-create" class="button button-secondary" type="submit" disabled>Create named worker</button>
|
||||
<p class="field-hint">A new worker starts immediately.</p>
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- RIGHT COLUMN — LOGS -->
|
||||
<div class="col-md-7 d-flex">
|
||||
<div class="card-dark w-100 d-flex flex-column">
|
||||
<div class="worker-workspace">
|
||||
<section id="worker-placeholder" class="panel worker-selection-empty">
|
||||
<div class="empty-state">
|
||||
<h2>Select a worker</h2>
|
||||
<p>Choose a worker to see its health, manage it and open its logs.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<h4>Logs</h4>
|
||||
<div class="d-flex gap-2">
|
||||
<button id="clear-logs" class="btn btn-outline-light btn-sm">Clear</button>
|
||||
<section id="control-centre" class="panel worker-controls" aria-labelledby="cc-name" hidden>
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<p class="eyebrow">Selected worker</p>
|
||||
<h2 id="cc-name"></h2>
|
||||
<p id="cc-sub" class="muted"></p>
|
||||
</div>
|
||||
<button id="clear-selection" class="button button-ghost" type="button">Deselect</button>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<dl class="worker-stats">
|
||||
<div><dt>CPU</dt><dd id="detail-cpu">—</dd></div>
|
||||
<div><dt>Memory</dt><dd id="detail-mem">—</dd></div>
|
||||
<div><dt>Uptime</dt><dd id="detail-uptime">—</dd></div>
|
||||
</dl>
|
||||
<div class="worker-actions" aria-label="Selected worker actions">
|
||||
<button id="btn-start" class="button button-primary" type="button" disabled>Start</button>
|
||||
<button id="btn-stop" class="button button-secondary" type="button" disabled>Stop</button>
|
||||
<button id="btn-restart" class="button button-secondary" type="button" disabled>Restart</button>
|
||||
<button id="btn-delete" class="button button-danger" type="button" disabled>Delete worker</button>
|
||||
</div>
|
||||
<details class="worker-details">
|
||||
<summary>Process details</summary>
|
||||
<dl>
|
||||
<div><dt>PM2 ID</dt><dd id="detail-pmid">—</dd></div>
|
||||
<div><dt>Process ID</dt><dd id="detail-pid">—</dd></div>
|
||||
<div><dt>Status</dt><dd id="detail-status">—</dd></div>
|
||||
<div><dt>Executable</dt><dd id="detail-exec">—</dd></div>
|
||||
</dl>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel log-panel" aria-labelledby="logs-title">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<h2 id="logs-title">Worker logs</h2>
|
||||
<p id="log-connection-state" class="muted" role="status" aria-live="polite">No worker selected</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="log-toolbar">
|
||||
<label class="checkbox-label" for="follow-logs"><input id="follow-logs" type="checkbox" checked> Follow output</label>
|
||||
<div class="worker-actions">
|
||||
<button id="reconnect-logs" class="button button-secondary button-small" type="button" disabled>Reconnect logs</button>
|
||||
<button id="clear-logs" class="button button-ghost button-small" type="button">Clear view</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="logs">[no logs yet]</div>
|
||||
|
||||
<pre id="logs" class="log-view" tabindex="0" aria-label="Worker log output" aria-live="off">Select a worker to view its logs.</pre>
|
||||
<p class="field-hint">The latest output stays here while you browse. Clearing this view does not delete stored logs.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const ws = new WebSocket((location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host);
|
||||
const logsEl = document.getElementById('logs');
|
||||
const actionOutput = document.getElementById('control-output');
|
||||
const MAX_VISIBLE_LOG = 64 * 1024;
|
||||
let selectedEl = null;
|
||||
let selectedData = null;
|
||||
let selectionGeneration = 0;
|
||||
let logWorkerName = null;
|
||||
let commandInFlight = false;
|
||||
|
||||
function appendLog(message) {
|
||||
const following = logsEl.scrollHeight - logsEl.scrollTop - logsEl.clientHeight < 40;
|
||||
const combined = logsEl.textContent + `[${new Date().toLocaleTimeString()}] ${String(message)}\n`;
|
||||
logsEl.textContent = combined.length > MAX_VISIBLE_LOG
|
||||
? '[earlier log output omitted]\n' + combined.slice(-MAX_VISIBLE_LOG)
|
||||
: combined;
|
||||
if (following) logsEl.scrollTop = logsEl.scrollHeight;
|
||||
}
|
||||
|
||||
function sendLogRequest(payload, showUnavailable = true) {
|
||||
if (ws.readyState !== WebSocket.OPEN) {
|
||||
if (showUnavailable) appendLog('[log connection is not ready]');
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ws.send(JSON.stringify(payload));
|
||||
return true;
|
||||
} catch {
|
||||
if (showUnavailable) appendLog('[log request could not be sent]');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function startSelectedLogs() {
|
||||
if (!selectedData || logWorkerName === selectedData.name) return;
|
||||
if (sendLogRequest({ type: 'logs', name: selectedData.name })) logWorkerName = selectedData.name;
|
||||
}
|
||||
|
||||
ws.addEventListener('open', () => {
|
||||
appendLog('[log connection ready]');
|
||||
startSelectedLogs();
|
||||
});
|
||||
ws.addEventListener('close', () => {
|
||||
logWorkerName = null;
|
||||
appendLog('[log connection closed; reload this page to reconnect]');
|
||||
});
|
||||
ws.addEventListener('error', () => appendLog('[log connection unavailable]'));
|
||||
ws.addEventListener('message', event => {
|
||||
let payload;
|
||||
try { payload = JSON.parse(event.data); } catch { return; }
|
||||
if (!payload || typeof payload !== 'object') return;
|
||||
if (payload.type === 'stdout' || payload.type === 'stderr') appendLog(payload.data || '');
|
||||
else if (payload.type === 'info') appendLog('[info] ' + (payload.message || ''));
|
||||
else if (payload.type === 'error') {
|
||||
logWorkerName = null;
|
||||
appendLog('[error] ' + (payload.error || 'The log stream failed.'));
|
||||
} else if (payload.type === 'close') {
|
||||
logWorkerName = null;
|
||||
appendLog('[log stream closed]');
|
||||
}
|
||||
});
|
||||
|
||||
function clearSelection() {
|
||||
selectionGeneration++;
|
||||
document.querySelectorAll('.pm2-row').forEach(row => row.classList.remove('active', 'selected-outline'));
|
||||
selectedEl = null;
|
||||
selectedData = null;
|
||||
logWorkerName = null;
|
||||
document.getElementById('control-centre').style.display = 'none';
|
||||
sendLogRequest({ type: 'stop-logs' }, false);
|
||||
}
|
||||
|
||||
function controlData(process) {
|
||||
return { ...process, pmid: process.pm_id ?? process.pmid ?? '—' };
|
||||
}
|
||||
|
||||
function populateControlCentre(data) {
|
||||
const values = {
|
||||
'cc-name': data.name,
|
||||
'cc-sub': `pm_id: ${data.pmid} • pid: ${data.pid} • status: ${data.status}`,
|
||||
'detail-name': data.name,
|
||||
'detail-pmid': data.pmid,
|
||||
'detail-pid': data.pid,
|
||||
'detail-status': data.status,
|
||||
'detail-uptime': data.uptime,
|
||||
'detail-cpu': data.cpu,
|
||||
'detail-mem': data.memoryMB,
|
||||
'detail-exec': data.execPath,
|
||||
};
|
||||
for (const [id, value] of Object.entries(values)) document.getElementById(id).textContent = value ?? '—';
|
||||
}
|
||||
|
||||
async function readProcesses() {
|
||||
const response = await fetch('/pm2/list-json', { cache: 'no-store' });
|
||||
const result = await response.json();
|
||||
if (!response.ok || !result.ok || !Array.isArray(result.processes)) throw new Error('The worker list is unavailable.');
|
||||
return result.processes;
|
||||
}
|
||||
|
||||
function bindRowEvents() {
|
||||
document.querySelectorAll('.pm2-row').forEach(row => {
|
||||
row.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
if (selectedEl === row) {
|
||||
clearSelection();
|
||||
return;
|
||||
}
|
||||
clearSelection();
|
||||
const requestGeneration = selectionGeneration;
|
||||
row.classList.add('active', 'selected-outline');
|
||||
selectedEl = row;
|
||||
selectedData = controlData({
|
||||
name: row.dataset.name,
|
||||
pmid: row.dataset.pmid,
|
||||
pid: row.dataset.pid,
|
||||
status: row.dataset.status,
|
||||
});
|
||||
populateControlCentre(selectedData);
|
||||
document.getElementById('control-centre').style.display = 'block';
|
||||
const name = selectedData.name;
|
||||
try {
|
||||
const full = (await readProcesses()).find(process => process.name === name);
|
||||
if (requestGeneration !== selectionGeneration || selectedData?.name !== name) return;
|
||||
if (!full) {
|
||||
clearSelection();
|
||||
actionOutput.textContent = 'The selected worker is no longer available.';
|
||||
return;
|
||||
}
|
||||
selectedData = controlData(full);
|
||||
populateControlCentre(selectedData);
|
||||
} catch {
|
||||
if (requestGeneration !== selectionGeneration || selectedData?.name !== name) return;
|
||||
actionOutput.textContent = 'Could not refresh the selected worker details.';
|
||||
}
|
||||
if (requestGeneration === selectionGeneration && selectedData?.name === name) startSelectedLogs();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function element(tag, className, text) {
|
||||
const node = document.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (text !== undefined) node.textContent = String(text ?? '—');
|
||||
return node;
|
||||
}
|
||||
|
||||
function processRow(process) {
|
||||
const row = element('a', 'list-group-item pm2-row d-flex justify-content-between');
|
||||
row.href = '#';
|
||||
row.dataset.name = String(process.name);
|
||||
row.dataset.pid = String(process.pid);
|
||||
row.dataset.pmid = String(process.pm_id);
|
||||
row.dataset.status = String(process.status);
|
||||
const status = String(process.status || '').toLowerCase();
|
||||
let badge = 'bg-secondary';
|
||||
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||
else if (status.includes('start') || status.includes('launch')) badge = 'bg-warning text-dark';
|
||||
const description = element('div');
|
||||
description.append(element('strong', '', process.name), ' ', element('span', 'badge badge-small ' + badge, process.status), element('div', 'subtle', process.execPath));
|
||||
const detail = element('div', 'text-end');
|
||||
detail.append(element('div', '', 'pid: ' + process.pid), element('div', 'subtle', process.uptime));
|
||||
row.append(description, detail);
|
||||
return row;
|
||||
}
|
||||
|
||||
async function refreshList() {
|
||||
try {
|
||||
const processes = await readProcesses();
|
||||
const list = document.getElementById('process-list');
|
||||
const selectedName = selectedData?.name;
|
||||
list.replaceChildren();
|
||||
for (const process of processes) {
|
||||
const row = processRow(process);
|
||||
list.appendChild(row);
|
||||
if (process.name === selectedName) {
|
||||
selectedEl = row;
|
||||
selectedData = controlData(process);
|
||||
row.classList.add('active', 'selected-outline');
|
||||
populateControlCentre(selectedData);
|
||||
}
|
||||
}
|
||||
if (!processes.length) list.appendChild(element('div', 'alert alert-warning', 'No downloader workers found.'));
|
||||
if (selectedName && !processes.some(process => process.name === selectedName)) clearSelection();
|
||||
bindRowEvents();
|
||||
return true;
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not refresh the worker list. Please try again.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function execCommand(payload) {
|
||||
if (commandInFlight) return false;
|
||||
commandInFlight = true;
|
||||
actionOutput.textContent = 'Running worker command…';
|
||||
try {
|
||||
const response = await fetch('/pm2/command', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const result = await response.json();
|
||||
actionOutput.textContent = result.message || result.error || 'The worker command could not be completed.';
|
||||
if (response.ok && result.ok) {
|
||||
await refreshList();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not contact the worker supervisor. Please try again.';
|
||||
return false;
|
||||
} finally {
|
||||
commandInFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function findNextWorkerName() {
|
||||
const names = new Set((await readProcesses()).map(process => process.name));
|
||||
let next = 1;
|
||||
while (names.has('proxerdl-worker' + next)) next++;
|
||||
return 'proxerdl-worker' + next;
|
||||
}
|
||||
|
||||
document.getElementById('btn-create').addEventListener('click', async event => {
|
||||
const button = event.currentTarget;
|
||||
if (button.disabled || commandInFlight) return;
|
||||
button.disabled = true;
|
||||
actionOutput.textContent = 'Preparing a downloader worker…';
|
||||
try {
|
||||
const name = await findNextWorkerName();
|
||||
if (await execCommand({ cmd: 'create', name })) {
|
||||
const row = [...document.querySelectorAll('.pm2-row')].find(item => item.dataset.name === name);
|
||||
if (row) row.click();
|
||||
}
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not prepare the worker. Refresh the list and try again.';
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
for (const command of ['start', 'stop', 'restart', 'delete']) {
|
||||
document.getElementById('btn-' + command).addEventListener('click', () => {
|
||||
if (!selectedData) {
|
||||
actionOutput.textContent = 'Select a downloader worker first.';
|
||||
return;
|
||||
}
|
||||
execCommand({ cmd: command, name: selectedData.name });
|
||||
});
|
||||
}
|
||||
document.getElementById('refresh-list').addEventListener('click', refreshList);
|
||||
document.getElementById('clear-logs').addEventListener('click', () => { logsEl.textContent = ''; });
|
||||
window.addEventListener('beforeunload', () => sendLogRequest({ type: 'stop-logs' }, false));
|
||||
bindRowEvents();
|
||||
</script>
|
||||
|
||||
<script src="/workers.js" defer></script>
|
||||
<%- include('partials/footer') %>
|
||||
Reference in new issue
Block a user