Commit 74b5be10 Harvey

任务函数包装 异常处理

1 个父辈 0ba2f8af
......@@ -58,6 +58,16 @@ function loadAllJSFiles(dirPaths, options = {}) {
});
return loadedModules;
}
function wrapper_task(func) {
return async function (...args) {
try {
return await func(...args);
}
catch (error) {
return { error: error.message };
}
};
}
(() => {
const modules = loadAllJSFiles(['./build/job'], {
ignoreNodeModules: true,
......@@ -72,7 +82,7 @@ function loadAllJSFiles(dirPaths, options = {}) {
console.log(key2 + '已存在');
continue;
}
job_handlers.set(key2, m[key2]);
job_handlers.set(key2, wrapper_task(m[key2]));
// console.log(key2)
}
}
......
......@@ -4,7 +4,7 @@
"description": "",
"main": "build/index.js",
"scripts": {
"start": "node ./build/index.js ",
"start": "node ./build/index.js",
"watch": "tsc -w",
"compile": "tsc"
},
......
......@@ -74,6 +74,17 @@ function loadAllJSFiles(dirPaths, options: any = {}) {
return loadedModules;
}
function wrapper_task(func) {
return async function (...args) {
try {
return await func(...args);
} catch (error) {
return { error: error.message };
}
};
}
(() => {
const modules = loadAllJSFiles(['./build/job'], {
......@@ -91,7 +102,8 @@ function loadAllJSFiles(dirPaths, options: any = {}) {
console.log(key2 + '已存在')
continue;
}
job_handlers.set(key2, m[key2])
job_handlers.set(key2, wrapper_task(m[key2]))
// console.log(key2)
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!