Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
424309e3c3 | ||
|
|
e5d640dc1a | ||
|
|
c5d2258f52 | ||
|
|
d7d1381259 | ||
|
|
eda319e16a | ||
|
|
a945cd80d3 | ||
|
|
2b693c2a69 | ||
|
|
abb4b9326f | ||
|
|
4cf3c084a9 |
No files matched your search
@@ -354,7 +354,7 @@ A workflow is a JSON definition with a list of steps, created on the **Workflows
|
|||||||
|
|
||||||
| Step type | Fields | What it does |
|
| Step type | Fields | What it does |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `execute` | `command`, `targets` (`["all"]` or worker names/ids; default all), `condition`, `timeout` (seconds, 5 to 600), `retries` (0 to 5), `retryDelayMs` | Runs the command on each target; a failure fails the workflow |
|
| `execute` | `command`, `targets` (`["all"]` or worker names/ids; default all), `condition`, `timeout` (seconds, 5 to 600), `retries` (0 to 5), `retryDelayMs`, `parallel` (default true) | Runs the command on all targets at once (`parallel: false`: one after another, stopping at the first failure); a failure on any target fails the workflow |
|
||||||
| `parse` | `condition` | Reads `KEY=VALUE` lines (key in capitals) from the last command's output into `state.key` (lower case) |
|
| `parse` | `condition` | Reads `KEY=VALUE` lines (key in capitals) from the last command's output into `state.key` (lower case) |
|
||||||
| `route` | `conditions`: `[{ "if", "goto", "label" }, { "default": true, "goto" }]` | Jumps to the first matching condition's step |
|
| `route` | `conditions`: `[{ "if", "goto", "label" }, { "default": true, "goto" }]` | Jumps to the first matching condition's step |
|
||||||
| `prompt` | `message`, `options`, `key`, `routes` (`{ "<option>": "<step id>" }`) | Waits for someone to answer in the UI (up to 60 min, never past the execution's time limit). An unanswered prompt fails the workflow |
|
| `prompt` | `message`, `options`, `key`, `routes` (`{ "<option>": "<step id>" }`) | Waits for someone to answer in the UI (up to 60 min, never past the execution's time limit). An unanswered prompt fails the workflow |
|
||||||
|
|||||||
@@ -250,3 +250,15 @@ html[data-theme="light"] .ex-cmp-head { background: var(--bg-secondary); }
|
|||||||
html[data-theme="light"] .ex-log-title { color: var(--text-primary); }
|
html[data-theme="light"] .ex-log-title { color: var(--text-primary); }
|
||||||
html[data-theme="light"] .ex-diff-same { color: var(--text-muted); }
|
html[data-theme="light"] .ex-diff-same { color: var(--text-muted); }
|
||||||
html[data-theme="light"] .ex-row.is-selected td { background: rgba(255, 179, 0, 0.18); }
|
html[data-theme="light"] .ex-row.is-selected td { background: rgba(255, 179, 0, 0.18); }
|
||||||
|
|
||||||
|
/* Command executions in the list: `command @ worker` (#15). */
|
||||||
|
.ex-row-cmd {
|
||||||
|
display: inline-block;
|
||||||
|
max-width: min(24rem, 100%);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
vertical-align: bottom;
|
||||||
|
color: var(--text-primary, inherit);
|
||||||
|
}
|
||||||
|
.ex-row-worker { color: var(--text-muted, inherit); white-space: nowrap; }
|
||||||
@@ -77,6 +77,8 @@
|
|||||||
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
|
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
|
||||||
if (view === 'manual') params.set('hide_internal', 'true');
|
if (view === 'manual') params.set('hide_internal', 'true');
|
||||||
if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4)
|
if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4)
|
||||||
|
const term = searchTerm();
|
||||||
|
if (term) params.set('search', term); // server-side (#16)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Pulse.api.get('/api/executions?' + params.toString());
|
const data = await Pulse.api.get('/api/executions?' + params.toString());
|
||||||
@@ -103,21 +105,20 @@
|
|||||||
// Live events trigger this; coalesce bursts into at most one reload per 2 s (#10).
|
// Live events trigger this; coalesce bursts into at most one reload per 2 s (#10).
|
||||||
const reloadCurrent = Pulse.util.throttle(reloadNow, 2000);
|
const reloadCurrent = Pulse.util.throttle(reloadNow, 2000);
|
||||||
|
|
||||||
|
// Typing in the search box: search on the server once typing pauses (#16).
|
||||||
|
let searchTimer = null;
|
||||||
|
function searchSoon() {
|
||||||
|
clearTimeout(searchTimer);
|
||||||
|
searchTimer = setTimeout(reloadNow, 300);
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
Rendering: list
|
Rendering: list
|
||||||
------------------------------------------------------------------ */
|
------------------------------------------------------------------ */
|
||||||
|
// Search runs on the server (it can see commands); status stays a local filter.
|
||||||
function filteredRows(view) {
|
function filteredRows(view) {
|
||||||
const term = searchTerm();
|
|
||||||
const status = statusTerm();
|
const status = statusTerm();
|
||||||
return state[view].rows.filter((e) => {
|
return state[view].rows.filter((e) => !status || displayStatus(e) === status);
|
||||||
if (status && displayStatus(e) !== status) return false;
|
|
||||||
if (term) {
|
|
||||||
const name = execName(e).toLowerCase();
|
|
||||||
const id = String(e.id || '').toLowerCase();
|
|
||||||
if (name.indexOf(term) === -1 && id.indexOf(term) === -1) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function countLabel(view) {
|
function countLabel(view) {
|
||||||
@@ -127,6 +128,13 @@
|
|||||||
return '(' + st.total + ')';
|
return '(' + st.total + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Workflows by name; commands as `command @ worker` instead of "[Quick Command]" (#15).
|
||||||
|
function nameCell(e) {
|
||||||
|
if (e.workflow_name || !e.command) return '<strong>' + esc(execName(e)) + '</strong>';
|
||||||
|
return '<code class="ex-row-cmd" title="' + esc(e.command) + '">' + esc(e.command) + '</code>' +
|
||||||
|
(e.worker_name ? ' <span class="ex-row-worker">@ ' + esc(e.worker_name) + '</span>' : '');
|
||||||
|
}
|
||||||
|
|
||||||
// 'waiting' when a running execution is blocked on a prompt (#3).
|
// 'waiting' when a running execution is blocked on a prompt (#3).
|
||||||
function displayStatus(e) {
|
function displayStatus(e) {
|
||||||
return e.status === 'running' && e.waiting_for_input ? 'waiting' : e.status;
|
return e.status === 'running' && e.waiting_for_input ? 'waiting' : e.status;
|
||||||
@@ -156,7 +164,7 @@
|
|||||||
' data-execution-id="' + esc(e.id) + '" tabindex="0">' +
|
' data-execution-id="' + esc(e.id) + '" tabindex="0">' +
|
||||||
check +
|
check +
|
||||||
'<td data-label="Status"><span class="' + Pulse.fmt.status(displayStatus(e)) + '">' + esc(displayStatus(e)) + '</span></td>' +
|
'<td data-label="Status"><span class="' + Pulse.fmt.status(displayStatus(e)) + '">' + esc(displayStatus(e)) + '</span></td>' +
|
||||||
'<td data-label="Name"><strong>' + esc(execName(e)) + '</strong></td>' +
|
'<td data-label="Name">' + nameCell(e) + '</td>' +
|
||||||
'<td data-label="Started by">' + esc(e.started_by || '') + '</td>' +
|
'<td data-label="Started by">' + esc(e.started_by || '') + '</td>' +
|
||||||
'<td data-label="Started">' + esc(Pulse.fmt.dateTime(e.started_at)) + '</td>' +
|
'<td data-label="Started">' + esc(Pulse.fmt.dateTime(e.started_at)) + '</td>' +
|
||||||
'<td data-label="Completed">' + completed + '</td>' +
|
'<td data-label="Completed">' + completed + '</td>' +
|
||||||
@@ -473,7 +481,11 @@
|
|||||||
'data-execution-id="' + esc(id) + '">⛔ Abort Execution</button>';
|
'data-execution-id="' + esc(id) + '">⛔ Abort Execution</button>';
|
||||||
}
|
}
|
||||||
const cmdLog = (Array.isArray(ex.logs) ? ex.logs : []).find((l) => l.action === 'command_sent' && l.command);
|
const cmdLog = (Array.isArray(ex.logs) ? ex.logs : []).find((l) => l.action === 'command_sent' && l.command);
|
||||||
if (cmdLog) {
|
if (ex.workflow_id) {
|
||||||
|
// A workflow re-runs as the whole workflow with its parameters, not its first command (#18).
|
||||||
|
html += '<button type="button" class="lt-btn lt-btn-secondary lt-btn-sm" data-action="ex:rerun-workflow" ' +
|
||||||
|
'data-execution-id="' + esc(id) + '">↻ Re-run Workflow</button>';
|
||||||
|
} else if (cmdLog) {
|
||||||
html += '<button type="button" class="lt-btn lt-btn-secondary lt-btn-sm" data-action="ex:rerun" ' +
|
html += '<button type="button" class="lt-btn lt-btn-secondary lt-btn-sm" data-action="ex:rerun" ' +
|
||||||
'data-command="' + esc(cmdLog.command) + '" data-worker-id="' + esc(cmdLog.worker_id || '') + '">' +
|
'data-command="' + esc(cmdLog.command) + '" data-worker-id="' + esc(cmdLog.worker_id || '') + '">' +
|
||||||
'↻ Re-run Command</button>';
|
'↻ Re-run Command</button>';
|
||||||
@@ -633,7 +645,7 @@
|
|||||||
setView(view);
|
setView(view);
|
||||||
},
|
},
|
||||||
|
|
||||||
'ex:search': () => { render(); },
|
'ex:search': () => { searchSoon(); },
|
||||||
'ex:filter-status': () => { render(); },
|
'ex:filter-status': () => { render(); },
|
||||||
|
|
||||||
'ex:clear-filters': () => {
|
'ex:clear-filters': () => {
|
||||||
@@ -641,7 +653,7 @@
|
|||||||
const st = $('ex-status');
|
const st = $('ex-status');
|
||||||
if (s) s.value = '';
|
if (s) s.value = '';
|
||||||
if (st) st.value = '';
|
if (st) st.value = '';
|
||||||
render();
|
reloadNow();
|
||||||
},
|
},
|
||||||
|
|
||||||
'ex:load-more': async (el) => {
|
'ex:load-more': async (el) => {
|
||||||
@@ -736,6 +748,37 @@
|
|||||||
window.location.href = '/quick';
|
window.location.href = '/quick';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'ex:rerun-workflow': async (el) => {
|
||||||
|
const id = el.getAttribute('data-execution-id');
|
||||||
|
if (!id) return;
|
||||||
|
let ex;
|
||||||
|
try {
|
||||||
|
ex = await Pulse.api.get('/api/executions/' + encodeURIComponent(id));
|
||||||
|
} catch (e) {
|
||||||
|
toast('error', (e && e.message) || 'Failed to load the execution');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const paramsLog = (Array.isArray(ex.logs) ? ex.logs : []).find((l) => l.action === 'params');
|
||||||
|
const params = (paramsLog && paramsLog.params) || {};
|
||||||
|
const names = Object.keys(params);
|
||||||
|
const ok = await askConfirm({
|
||||||
|
title: 'Re-run Workflow',
|
||||||
|
message: 'Run ' + ((state.rowIndex.get(id) || {}).workflow_name || 'this workflow') + ' again' +
|
||||||
|
(names.length ? ' with the same parameters?\n\n' + names.map((k) => k + ' = ' + params[k]).join('\n') : '?'),
|
||||||
|
type: 'warning',
|
||||||
|
confirmLabel: 'RE-RUN',
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
const started = await Pulse.api.post('/api/executions', { workflow_id: ex.workflow_id, params: params });
|
||||||
|
toast('success', 'Workflow started');
|
||||||
|
openDetail(started.id, false);
|
||||||
|
reloadNow();
|
||||||
|
} catch (e) {
|
||||||
|
toast('error', (e && e.message) || 'Failed to start the workflow');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
'ex:download': async (el) => {
|
'ex:download': async (el) => {
|
||||||
const id = el.getAttribute('data-execution-id') || openDetailId();
|
const id = el.getAttribute('data-execution-id') || openDetailId();
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|||||||
@@ -248,21 +248,19 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
renderExecuting(workerIds.length);
|
renderExecuting(workerIds.length);
|
||||||
const results = [];
|
// Send to every selected worker at once (#26); results keep the selection order.
|
||||||
let successCount = 0;
|
const results = await Promise.all(workerIds.map(async (workerId) => {
|
||||||
let failCount = 0;
|
|
||||||
for (const workerId of workerIds) {
|
|
||||||
const worker = _workers.find(w => w.id === workerId);
|
const worker = _workers.find(w => w.id === workerId);
|
||||||
const workerLabel = worker ? worker.name : workerId;
|
const workerLabel = worker ? worker.name : workerId;
|
||||||
try {
|
try {
|
||||||
const data = await Pulse.api.post('/api/workers/' + encodeURIComponent(workerId) + '/command', { command });
|
const data = await Pulse.api.post('/api/workers/' + encodeURIComponent(workerId) + '/command', { command });
|
||||||
results.push({ worker: workerLabel, success: true, executionId: data && data.execution_id });
|
return { worker: workerLabel, success: true, executionId: data && data.execution_id };
|
||||||
successCount++;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
results.push({ worker: workerLabel, success: false, error: e.message || 'Failed to execute' });
|
return { worker: workerLabel, success: false, error: e.message || 'Failed to execute' };
|
||||||
failCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
|
const successCount = results.filter(r => r.success).length;
|
||||||
|
const failCount = results.length - successCount;
|
||||||
addToHistory(command, workerIds.length + ' workers');
|
addToHistory(command, workerIds.length + ' workers');
|
||||||
renderMultiResult(results, successCount, failCount);
|
renderMultiResult(results, successCount, failCount);
|
||||||
if (failCount === 0) Pulse.beep('success');
|
if (failCount === 0) Pulse.beep('success');
|
||||||
|
|||||||
@@ -795,6 +795,14 @@ function broadcast(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to add log entry to execution (atomic: no read-modify-write race condition)
|
// Helper function to add log entry to execution (atomic: no read-modify-write race condition)
|
||||||
|
// One readable message for the UI, which shows only `error` (#25):
|
||||||
|
// "Invalid workflow definition: step check: no step with id "nope"".
|
||||||
|
function definitionError(problems) {
|
||||||
|
const parts = problems.slice(0, 5).map(p => `step ${p.step}: ${p.error}`);
|
||||||
|
if (problems.length > 5) parts.push(`and ${problems.length - 5} more`);
|
||||||
|
return 'Invalid workflow definition: ' + parts.join('; ');
|
||||||
|
}
|
||||||
|
|
||||||
async function addExecutionLog(executionId, logEntry) {
|
async function addExecutionLog(executionId, logEntry) {
|
||||||
try {
|
try {
|
||||||
await pool.query(
|
await pool.query(
|
||||||
@@ -1263,13 +1271,17 @@ async function executeCommandStep(executionId, step, stepNumber, params = {}) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute command on each target worker and wait for results
|
// Per-step timeout override: step.timeout (seconds) overrides global default
|
||||||
const results = [];
|
const stepTimeoutMs = step.timeout
|
||||||
let sentCount = 0;
|
? Math.min(Math.max(parseInt(step.timeout, 10) * 1000, 5000), 600000)
|
||||||
|
: COMMAND_TIMEOUT_MS;
|
||||||
|
// Per-step retry: step.retries (default 0) with step.retryDelayMs (default 2000)
|
||||||
|
const maxRetries = Math.min(parseInt(step.retries || 0, 10), 5);
|
||||||
|
const retryDelayMs = Math.min(parseInt(step.retryDelayMs || 2000, 10), 30000);
|
||||||
|
|
||||||
for (const workerId of targetWorkerIds) {
|
// Runs the command on one worker (with retries): { sent, success }.
|
||||||
|
const runOnWorker = async (workerId) => {
|
||||||
const workerWs = workers.get(workerId);
|
const workerWs = workers.get(workerId);
|
||||||
|
|
||||||
if (!workerWs || workerWs.readyState !== WebSocket.OPEN) {
|
if (!workerWs || workerWs.readyState !== WebSocket.OPEN) {
|
||||||
await addExecutionLog(executionId, {
|
await addExecutionLog(executionId, {
|
||||||
step: stepNumber,
|
step: stepNumber,
|
||||||
@@ -1277,13 +1289,10 @@ async function executeCommandStep(executionId, step, stepNumber, params = {}) {
|
|||||||
worker_id: workerId,
|
worker_id: workerId,
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
});
|
});
|
||||||
continue;
|
return { sent: false, success: false };
|
||||||
}
|
}
|
||||||
sentCount++;
|
|
||||||
|
|
||||||
// Send command to worker
|
|
||||||
let commandId = crypto.randomUUID();
|
let commandId = crypto.randomUUID();
|
||||||
|
|
||||||
await addExecutionLog(executionId, {
|
await addExecutionLog(executionId, {
|
||||||
step: stepNumber,
|
step: stepNumber,
|
||||||
action: 'command_sent',
|
action: 'command_sent',
|
||||||
@@ -1292,12 +1301,6 @@ async function executeCommandStep(executionId, step, stepNumber, params = {}) {
|
|||||||
command_id: commandId,
|
command_id: commandId,
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Per-step timeout override: step.timeout (seconds) overrides global default
|
|
||||||
const stepTimeoutMs = step.timeout
|
|
||||||
? Math.min(Math.max(parseInt(step.timeout, 10) * 1000, 5000), 600000)
|
|
||||||
: COMMAND_TIMEOUT_MS;
|
|
||||||
|
|
||||||
sendCommandToWorker(workerWs, {
|
sendCommandToWorker(workerWs, {
|
||||||
type: 'execute_command',
|
type: 'execute_command',
|
||||||
execution_id: executionId,
|
execution_id: executionId,
|
||||||
@@ -1307,10 +1310,6 @@ async function executeCommandStep(executionId, step, stepNumber, params = {}) {
|
|||||||
timeout: stepTimeoutMs
|
timeout: stepTimeoutMs
|
||||||
});
|
});
|
||||||
|
|
||||||
// Per-step retry: step.retries (default 0) with step.retryDelayMs (default 2000)
|
|
||||||
const maxRetries = Math.min(parseInt(step.retries || 0, 10), 5);
|
|
||||||
const retryDelayMs = Math.min(parseInt(step.retryDelayMs || 2000, 10), 30000);
|
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
let attempt = 0;
|
let attempt = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -1340,13 +1339,25 @@ async function executeCommandStep(executionId, step, stepNumber, params = {}) {
|
|||||||
});
|
});
|
||||||
commandId = retryCommandId; // update for next waitForCommandResult call
|
commandId = retryCommandId; // update for next waitForCommandResult call
|
||||||
}
|
}
|
||||||
results.push(result);
|
return { sent: true, success: !!result.success };
|
||||||
|
};
|
||||||
|
|
||||||
if (!result.success) {
|
// All targets at once (#26), so one slow or hung worker doesn't hold up the
|
||||||
// Command failed after all retries, workflow should stop
|
// rest. `parallel: false` keeps the old one-at-a-time order for rolling changes,
|
||||||
return false;
|
// stopping at the first failure.
|
||||||
|
let outcomes;
|
||||||
|
if (step.parallel === false) {
|
||||||
|
outcomes = [];
|
||||||
|
for (const workerId of targetWorkerIds) {
|
||||||
|
const o = await runOnWorker(workerId);
|
||||||
|
outcomes.push(o);
|
||||||
|
if (o.sent && !o.success) return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
outcomes = await Promise.all(targetWorkerIds.map(runOnWorker));
|
||||||
|
if (outcomes.some(o => o.sent && !o.success)) return false;
|
||||||
}
|
}
|
||||||
|
const sentCount = outcomes.filter(o => o.sent).length;
|
||||||
|
|
||||||
// If every target worker was offline, treat as step failure
|
// If every target worker was offline, treat as step failure
|
||||||
if (sentCount === 0) {
|
if (sentCount === 0) {
|
||||||
@@ -1516,7 +1527,7 @@ app.post('/api/workflows', authenticateSSO, requireJSON, async (req, res) => {
|
|||||||
const { name, description, definition, webhook_url } = req.body;
|
const { name, description, definition, webhook_url } = req.body;
|
||||||
if (!name || !definition) return res.status(400).json({ error: 'name and definition are required' });
|
if (!name || !definition) return res.status(400).json({ error: 'name and definition are required' });
|
||||||
const problems = [...conditionErrors(definition), ...gotoErrors(definition)];
|
const problems = [...conditionErrors(definition), ...gotoErrors(definition)];
|
||||||
if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems });
|
if (problems.length) return res.status(400).json({ error: definitionError(problems), problems });
|
||||||
|
|
||||||
const webhookCheck = validateWebhookUrl(webhook_url);
|
const webhookCheck = validateWebhookUrl(webhook_url);
|
||||||
if (!webhookCheck.ok) return res.status(400).json({ error: webhookCheck.reason });
|
if (!webhookCheck.ok) return res.status(400).json({ error: webhookCheck.reason });
|
||||||
@@ -1682,18 +1693,23 @@ app.get('/api/executions', authenticateSSO, async (req, res) => {
|
|||||||
queryParams.push(new Date(req.query.before));
|
queryParams.push(new Date(req.query.before));
|
||||||
}
|
}
|
||||||
if (req.query.search) {
|
if (req.query.search) {
|
||||||
conditions.push('(w.name LIKE ? OR e.started_by LIKE ?)');
|
// Workflow name, who started it, the id, or any command it ran (#16).
|
||||||
const term = `%${req.query.search}%`;
|
conditions.push("(w.name LIKE ? OR e.started_by LIKE ? OR e.id LIKE ? OR JSON_SEARCH(e.logs, 'one', ?, NULL, '$[*].command') IS NOT NULL)");
|
||||||
queryParams.push(term, term);
|
const term = `%${String(req.query.search).slice(0, 200)}%`;
|
||||||
|
queryParams.push(term, term, term, term);
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereClause = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
const whereClause = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
||||||
|
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
`SELECT e.id, e.workflow_id, e.status, e.started_by, e.started_at, e.completed_at,
|
`SELECT e.id, e.workflow_id, e.status, e.started_by, e.started_at, e.completed_at,
|
||||||
w.name as workflow_name
|
w.name as workflow_name,
|
||||||
|
-- What a command execution ran, and where (#15): its first log entry.
|
||||||
|
IF(e.workflow_id IS NULL, LEFT(JSON_UNQUOTE(JSON_EXTRACT(e.logs, '$[0].command')), 500), NULL) AS command,
|
||||||
|
IF(e.workflow_id IS NULL, wk.name, NULL) AS worker_name
|
||||||
FROM executions e
|
FROM executions e
|
||||||
LEFT JOIN workflows w ON e.workflow_id = w.id
|
LEFT JOIN workflows w ON e.workflow_id = w.id
|
||||||
|
LEFT JOIN workers wk ON e.workflow_id IS NULL AND wk.id = JSON_UNQUOTE(JSON_EXTRACT(e.logs, '$[0].worker_id'))
|
||||||
${whereClause}
|
${whereClause}
|
||||||
ORDER BY e.started_at DESC LIMIT ? OFFSET ?`,
|
ORDER BY e.started_at DESC LIMIT ? OFFSET ?`,
|
||||||
[...queryParams, limit, offset]
|
[...queryParams, limit, offset]
|
||||||
@@ -1856,7 +1872,7 @@ app.put('/api/workflows/:id', authenticateSSO, requireJSON, async (req, res) =>
|
|||||||
return res.status(400).json({ error: 'Invalid JSON in definition' });
|
return res.status(400).json({ error: 'Invalid JSON in definition' });
|
||||||
}
|
}
|
||||||
const problems = [...conditionErrors(defObj), ...gotoErrors(defObj)];
|
const problems = [...conditionErrors(defObj), ...gotoErrors(defObj)];
|
||||||
if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems });
|
if (problems.length) return res.status(400).json({ error: definitionError(problems), problems });
|
||||||
|
|
||||||
const [result] = await pool.query(
|
const [result] = await pool.query(
|
||||||
'UPDATE workflows SET name=?, description=?, definition=?, webhook_url=?, updated_at=NOW() WHERE id=?',
|
'UPDATE workflows SET name=?, description=?, definition=?, webhook_url=?, updated_at=NOW() WHERE id=?',
|
||||||
|
|||||||
@@ -65,3 +65,22 @@ test('the Automated and Manual views filter on the server (#4)', async () => {
|
|||||||
expect(manual.executions.some(e => automated(e.started_by))).toBe(false);
|
expect(manual.executions.some(e => automated(e.started_by))).toBe(false);
|
||||||
expect(auto.executions.some(e => e.id === submit.json.execution_id)).toBe(true);
|
expect(auto.executions.some(e => e.id === submit.json.execution_id)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('execution search finds runs by the command they ran (#16)', async () => {
|
||||||
|
const marker = `srch-${Date.now().toString(36)}`;
|
||||||
|
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: `echo ${marker}` });
|
||||||
|
await waitForExecution(submit.json.execution_id);
|
||||||
|
const hit = (await sso('GET', `/api/executions?search=${marker}&limit=50`)).json;
|
||||||
|
expect(hit.executions.map(e => e.id)).toEqual([submit.json.execution_id]);
|
||||||
|
const byId = (await sso('GET', `/api/executions?search=${submit.json.execution_id.slice(0, 13)}`)).json;
|
||||||
|
expect(byId.executions.map(e => e.id)).toContain(submit.json.execution_id);
|
||||||
|
expect((await sso('GET', '/api/executions?search=no-such-command-anywhere')).json.executions).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the execution list says what a command ran and where (#15)', async () => {
|
||||||
|
const marker = `sum-${Date.now().toString(36)}`;
|
||||||
|
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: `echo ${marker}` });
|
||||||
|
await waitForExecution(submit.json.execution_id);
|
||||||
|
const row = (await sso('GET', `/api/executions?search=${marker}`)).json.executions[0];
|
||||||
|
expect(row).toMatchObject({ command: `echo ${marker}`, worker_name: 'node-01' });
|
||||||
|
});
|
||||||
@@ -227,3 +227,41 @@ test('the execution list marks runs waiting on a prompt (#3)', async () => {
|
|||||||
await waitForExecution(id);
|
await waitForExecution(id);
|
||||||
expect((await row()).waiting_for_input).toBe(false);
|
expect((await row()).waiting_for_input).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a step runs on all its targets at once (#26)', async () => {
|
||||||
|
const t0 = Date.now();
|
||||||
|
const ex = await waitForExecution(await start(await createWorkflow([
|
||||||
|
{ id: 'slow', type: 'execute', command: 'sleep 2; echo done', targets: ['all'] },
|
||||||
|
])));
|
||||||
|
expect(ex.status).toBe('completed');
|
||||||
|
expect(outputs(ex).filter(o => o === 'done')).toHaveLength(3);
|
||||||
|
expect(Date.now() - t0).toBeLessThan(5500); // in sequence it would take 6 s or more
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parallel: false runs the targets one after another (#26)', async () => {
|
||||||
|
const t0 = Date.now();
|
||||||
|
const ex = await waitForExecution(await start(await createWorkflow([
|
||||||
|
{ id: 'slow', type: 'execute', command: 'sleep 2; echo done', targets: ['all'], parallel: false },
|
||||||
|
])), { timeout: 30_000 });
|
||||||
|
expect(ex.status).toBe('completed');
|
||||||
|
expect(Date.now() - t0).toBeGreaterThanOrEqual(6000);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a failure on one target fails the step, after every target has reported (#26)', async () => {
|
||||||
|
const ex = await waitForExecution(await start(await createWorkflow([
|
||||||
|
{ id: 'one-bad', type: 'execute', command: 'test "$WORKER_NAME" != node-02 && echo ok', targets: ['all'] },
|
||||||
|
{ id: 'after', type: 'execute', command: 'echo should-not-run', targets: ['node-01'] },
|
||||||
|
])));
|
||||||
|
expect(ex.status).toBe('failed');
|
||||||
|
expect(outputs(ex).filter(o => o === 'ok')).toHaveLength(2);
|
||||||
|
expect(outputs(ex)).not.toContain('should-not-run');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a rejected definition says what is wrong in the error itself (#25)', async () => {
|
||||||
|
const res = await sso('POST', '/api/workflows', { name: `bad-goto-${unique()}`, definition: { steps: [
|
||||||
|
{ id: 'check', type: 'execute', command: 'true', goto: 'nope' },
|
||||||
|
] } });
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
expect(res.json.error).toBe('Invalid workflow definition: step check: no step with id "nope"');
|
||||||
|
expect(res.json.problems).toHaveLength(1);
|
||||||
|
});
|
||||||
@@ -21,6 +21,10 @@ test('a quick command runs on a worker and its output shows in Executions', asyn
|
|||||||
const detail = page.locator('#ex-detail-body');
|
const detail = page.locator('#ex-detail-body');
|
||||||
await expect(detail).toContainText(marker);
|
await expect(detail).toContainText(marker);
|
||||||
await expect(detail).toContainText(/completed/i);
|
await expect(detail).toContainText(/completed/i);
|
||||||
|
|
||||||
|
// The list row says what ran and where, not just "[Quick Command]" (#15).
|
||||||
|
await page.keyboard.press('Escape');
|
||||||
|
await expect(page.locator('#ex-list-manual .ex-row').filter({ hasText: `echo ${marker}` }).first()).toContainText('@ node-02');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a failing command is reported as failed with its stderr', async ({ page }) => {
|
test('a failing command is reported as failed with its stderr', async ({ page }) => {
|
||||||
@@ -63,3 +67,16 @@ test('Executions updates live when a command starts elsewhere', async ({ page, r
|
|||||||
// Its own row appears without a reload (by id, so it works however full the list is).
|
// Its own row appears without a reload (by id, so it works however full the list is).
|
||||||
await expect(page.locator(`#ex-list-manual .ex-row[data-execution-id="${id}"]`)).toBeVisible();
|
await expect(page.locator(`#ex-list-manual .ex-row[data-execution-id="${id}"]`)).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('searching Executions finds a run by its command (#16)', async ({ page, request }) => {
|
||||||
|
const marker = token();
|
||||||
|
const workers = await (await request.get('/api/workers')).json();
|
||||||
|
const node1 = workers.find(w => w.name === 'node-01');
|
||||||
|
const { execution_id: id } = await (await request.post(`/api/workers/${node1.id}/command`, { data: { command: `echo ${marker}` } })).json();
|
||||||
|
|
||||||
|
await page.goto('/executions');
|
||||||
|
await page.locator('#ex-search').fill(marker);
|
||||||
|
const rows = page.locator('#ex-list-manual .ex-row');
|
||||||
|
await expect(rows).toHaveCount(1);
|
||||||
|
await expect(rows.first()).toHaveAttribute('data-execution-id', id);
|
||||||
|
});
|
||||||
@@ -43,6 +43,30 @@ test('an invalid workflow definition is rejected with a message', async ({ page,
|
|||||||
expect(problems).toEqual([]); // rejected in the browser, so no failed request either
|
expect(problems).toEqual([]); // rejected in the browser, so no failed request either
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a definition the server rejects shows the server\'s reason (#25)', async ({ page, problems }) => {
|
||||||
|
await page.goto('/workflows');
|
||||||
|
await page.getByRole('button', { name: '+ Create Workflow' }).click();
|
||||||
|
await page.locator('#wf-create-name').fill(`Bad goto ${Date.now()}`);
|
||||||
|
await page.locator('#wf-create-definition').fill(JSON.stringify({ steps: [
|
||||||
|
{ id: 'check', type: 'execute', command: 'true', goto: 'nope' },
|
||||||
|
] }));
|
||||||
|
await page.locator('#wf-create-form').getByRole('button', { name: 'Create' }).click();
|
||||||
|
await expect(page.locator('#wf-create-error')).toContainText('no step with id "nope"');
|
||||||
|
// The 400 (and the browser's console line for it) is the point of this test.
|
||||||
|
expect(problems.every(p => /400/.test(p))).toBe(true);
|
||||||
|
problems.length = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Escape closes the Run dialog (#25)', async ({ page, request }) => {
|
||||||
|
const name = `UI esc ${Date.now()}`;
|
||||||
|
await request.post('/api/workflows', { data: { name, definition: { steps: [{ id: 'a', type: 'execute', command: 'true' }] } } });
|
||||||
|
await page.goto('/workflows');
|
||||||
|
await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click();
|
||||||
|
await expect(page.locator('#wf-run-modal')).toBeVisible();
|
||||||
|
await page.keyboard.press('Escape');
|
||||||
|
await expect(page.locator('#wf-run-modal')).toBeHidden();
|
||||||
|
});
|
||||||
|
|
||||||
test('a run waiting on a prompt shows as waiting, and the Waiting filter finds it (#3)', async ({ page, request }) => {
|
test('a run waiting on a prompt shows as waiting, and the Waiting filter finds it (#3)', async ({ page, request }) => {
|
||||||
const created = await request.post('/api/workflows', { data: { name: `UI wait ${Date.now()}`, definition: { steps: [
|
const created = await request.post('/api/workflows', { data: { name: `UI wait ${Date.now()}`, definition: { steps: [
|
||||||
{ id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },
|
{ id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },
|
||||||
@@ -58,3 +82,42 @@ test('a run waiting on a prompt shows as waiting, and the Waiting filter finds i
|
|||||||
|
|
||||||
await request.post(`/api/executions/${ex}/respond`, { data: { response: 'Yes' } });
|
await request.post(`/api/executions/${ex}/respond`, { data: { response: 'Yes' } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the Create Workflow dialog starts with the example definition (#12)', async ({ page }) => {
|
||||||
|
await page.goto('/workflows');
|
||||||
|
await page.getByRole('button', { name: '+ Create Workflow' }).click();
|
||||||
|
const def = JSON.parse(await page.locator('#wf-create-definition').inputValue());
|
||||||
|
expect(Array.isArray(def.steps) && def.steps.length).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a workflow without parameters can still be dry-run (#13)', async ({ page, request }) => {
|
||||||
|
const name = `UI noparams ${Date.now()}`;
|
||||||
|
await request.post('/api/workflows', { data: { name, definition: { steps: [
|
||||||
|
{ id: 'a', type: 'execute', command: 'echo hi', targets: ['node-01'] },
|
||||||
|
] } } });
|
||||||
|
await page.goto('/workflows');
|
||||||
|
await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click();
|
||||||
|
await expect(page.locator('#wf-run-dryrun')).toBeVisible();
|
||||||
|
await page.locator('#wf-run-dryrun').check();
|
||||||
|
await page.locator('#wf-run-form').getByRole('button', { name: /Run/ }).click();
|
||||||
|
await expect(page.locator('#ex-detail-body')).toContainText(/dry run/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a workflow execution re-runs as the whole workflow with its parameters (#18)', async ({ page, request }) => {
|
||||||
|
const name = `UI rerun ${Date.now()}`;
|
||||||
|
const wf = (await (await request.post('/api/workflows', { data: { name, definition: {
|
||||||
|
params: [{ name: 'who', required: true }],
|
||||||
|
steps: [{ id: 'a', type: 'execute', command: 'echo hello {{who}}', targets: ['node-01'] }],
|
||||||
|
} } })).json()).id;
|
||||||
|
const first = (await (await request.post('/api/executions', { data: { workflow_id: wf, params: { who: 'world' } } })).json()).id;
|
||||||
|
|
||||||
|
await page.goto(`/executions?open=${first}`);
|
||||||
|
await expect(page.locator('#ex-detail-body')).toContainText('hello world');
|
||||||
|
await page.getByRole('button', { name: /Re-run Workflow/ }).click();
|
||||||
|
await page.getByRole('button', { name: 'RE-RUN', exact: true }).click();
|
||||||
|
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const list = await (await request.get('/api/executions?hide_internal=true&limit=20')).json();
|
||||||
|
return list.executions.filter(e => e.workflow_id === wf).length;
|
||||||
|
}).toBe(2);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user