shuzhiren-comfyui/任务队列后端/worker_threads/result/recordTask.js

29 lines
718 B
JavaScript

// recordTask.js
import { parentPort } from 'worker_threads'
import { record } from '../../outside/record.js'
async function recordTask(tasks) {
const recordTasks = []
for (const task of tasks) {
// 对每个task执行record函数
const recordTaskPromise = record(task)
recordTasks.push(recordTaskPromise)
}
try {
await Promise.all(recordTasks)
} catch (error) {
console.error('Error:', error)
throw error // 重新抛出错误以便上层处理
}
}
parentPort.on('message', async (tasks) => {
try {
await recordTask(tasks)
parentPort.postMessage({ status: 'completed' })
} catch (error) {
parentPort.postMessage({ status: 'error', error: error.message })
}
})