feat(card): jobs / capture queue
This commit is contained in:
28
public/views/cards/jobs.js
Normal file
28
public/views/cards/jobs.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// public/views/cards/jobs.js
|
||||
import { el, mount } from '../../dom.js';
|
||||
import { api } from '../../api.js';
|
||||
|
||||
let body, timer;
|
||||
async function load() {
|
||||
if (!body) return;
|
||||
try {
|
||||
const jobs = await api.get('/api/jobs?limit=100'); // flat array of {name,state,...}
|
||||
const counts = {};
|
||||
for (const j of jobs) counts[j.state] = (counts[j.state] || 0) + 1;
|
||||
const rows = ['active', 'created', 'retry', 'completed', 'failed']
|
||||
.filter(s => counts[s])
|
||||
.map(s => el('div', { class: 'sv-row' }, el('span', { class: 'k' }, s), el('span', {}, String(counts[s]))));
|
||||
mount(body,
|
||||
rows.length ? rows : el('span', { class: 'muted' }, 'No jobs'),
|
||||
el('a', { href: '#/jobs', class: 'k', style: { display: 'block', marginTop: '8px' } }, 'Open Jobs →')
|
||||
);
|
||||
} catch (e) {
|
||||
mount(body, el('span', { class: 'muted' }, e.status === 403 ? 'Owner only' : 'Jobs unavailable'));
|
||||
}
|
||||
}
|
||||
export default {
|
||||
id: 'jobs', title: 'Capture Queue', size: 'm',
|
||||
mount(el_) { body = el_; load(); },
|
||||
start() { timer = setInterval(load, 10000); },
|
||||
stop() { clearInterval(timer); body = null; }
|
||||
};
|
||||
Reference in New Issue
Block a user