@abtnode/queue 1.17.7-beta-20251223-090654-55d57623 → 1.17.7-beta-20251225-073259-cb6ecf68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +19 -2
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const tryWithTimeout = require('@abtnode/util/lib/try-with-timeout');
|
|
|
7
7
|
const sleep = require('@abtnode/util/lib/sleep');
|
|
8
8
|
|
|
9
9
|
const NedbStore = require('./store/nedb');
|
|
10
|
-
const
|
|
10
|
+
const defaultLogger = require('./logger');
|
|
11
11
|
|
|
12
12
|
const CANCELLED = '__CANCELLED__';
|
|
13
13
|
const MIN_DELAY = process.env.NODE_ENV === 'test' ? 2 : 5;
|
|
@@ -36,6 +36,15 @@ const MIN_DELAY = process.env.NODE_ENV === 'test' ? 2 : 5;
|
|
|
36
36
|
* @param {boolean} [config.options.enableScheduledJob] [param=false] enable scheduled job or not, default is false
|
|
37
37
|
*/
|
|
38
38
|
module.exports = function createQueue({ file, store, onJob, options = {} }) {
|
|
39
|
+
const requiredMethods = ['error', 'warn', 'info', 'debug', 'verbose', 'silly'];
|
|
40
|
+
const logger = requiredMethods.reduce((acc, method) => {
|
|
41
|
+
acc[method] =
|
|
42
|
+
options.logger?.[method] && typeof options.logger[method] === 'function'
|
|
43
|
+
? (...args) => options.logger[method](...args)
|
|
44
|
+
: defaultLogger[method];
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
|
|
39
48
|
if (!file && !store) {
|
|
40
49
|
throw new Error('Either nedb file path or store instance must be provided to create a queue');
|
|
41
50
|
}
|
|
@@ -90,7 +99,15 @@ module.exports = function createQueue({ file, store, onJob, options = {} }) {
|
|
|
90
99
|
}
|
|
91
100
|
|
|
92
101
|
try {
|
|
93
|
-
const result = await tryWithTimeout(() =>
|
|
102
|
+
const result = await tryWithTimeout(async () => {
|
|
103
|
+
try {
|
|
104
|
+
await onJob(job);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
// @note: 这里必须要输出错误,当我们在 onJob 里面使用 throw new Error() 的时候,它不是一次 request,错误根本就不会输出到日志,这会让排查变得异常困难
|
|
107
|
+
console.error('onJob.error', error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}, maxTimeout);
|
|
94
111
|
cb(null, result);
|
|
95
112
|
} catch (err) {
|
|
96
113
|
cb(err);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.7-beta-
|
|
6
|
+
"version": "1.17.7-beta-20251225-073259-cb6ecf68",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
18
18
|
"license": "Apache-2.0",
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "16715912460ed534e1e023d7e968714e3990051d",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/db": "1.17.7-beta-
|
|
22
|
-
"@abtnode/util": "1.17.7-beta-
|
|
21
|
+
"@abtnode/db": "1.17.7-beta-20251225-073259-cb6ecf68",
|
|
22
|
+
"@abtnode/util": "1.17.7-beta-20251225-073259-cb6ecf68",
|
|
23
23
|
"@blocklet/error": "^0.3.5",
|
|
24
24
|
"debug": "^4.4.1",
|
|
25
25
|
"fastq": "^1.17.1",
|
|
26
26
|
"uuid": "^11.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@abtnode/models": "1.17.7-beta-
|
|
29
|
+
"@abtnode/models": "1.17.7-beta-20251225-073259-cb6ecf68"
|
|
30
30
|
}
|
|
31
31
|
}
|