import http from 'http'; const PORT = 17311; async function callApi(path, options = {}) { const m = options.method || 'GET'; const body = options.body ? JSON.stringify(options.body) : null; const h = body ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) } : {}; return new Promise((resolve, reject) => { const req = http.request(`http://127.0.0.1:${PORT}${path}`, { method: m, headers: h }, (res) => { const c = []; res.on('data', x => c.push(x)); res.on('end', () => { try { resolve(JSON.parse(Buffer.concat(c).toString('utf-8'))); } catch { resolve({}); } }); }); req.on('error', reject); if (body) req.write(body); req.end(); }); } // 连续提交 4 个任务 const tasks = []; for (let i = 1; i <= 4; i++) { const body = { ip: '192.168.8.241', port: 7681, httpPort: 80, user: 'admin', pass: 'ky666888', channel: 33, start: '2026-07-08T10:00:00', end: '2026-07-08T10:00:10', speed: 4, outputPrefix: `batch${i}` }; const r = await callApi('/api/hikvision/download', { method: 'POST', body }); console.log(`#${i} ${r.taskId.slice(-10)} ${r.status}`); tasks.push(r.taskId); } console.log('\n=== 调度状态(并发上限 2) ==='); const start = Date.now(); for (let round = 0; round < 60; round++) { await new Promise(r => setTimeout(r, 1500)); const list = await callApi('/api/hikvision/tasks?pageSize=10'); const t = ((Date.now() - start) / 1000).toFixed(0) + 's'; const statuses = (list.data?.list || []).filter(x => tasks.includes(x.task_id)) .map(x => `${x.task_id.slice(-8)}:${x.status}`).join(' | '); console.log(`[${t}] ${statuses}`); const running = (list.data?.list || []).filter(x => tasks.includes(x.task_id) && x.status === 'running').length; const done = (list.data?.list || []).filter(x => tasks.includes(x.task_id) && (x.status === 'completed' || x.status === 'done')).length; if (done === 4) { console.log('\n全部完成!'); break; } }