@abtnode/queue 1.16.11-next-48aec895 → 1.16.11-next-9f5464a1
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 +16 -1
- package/lib/store/nedb.js +3 -2
- package/lib/store/sequelize.js +4 -2
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-return-assign */
|
|
1
2
|
/* eslint-disable no-underscore-dangle */
|
|
2
3
|
const uuid = require('uuid');
|
|
3
4
|
const Queue = require('fastq');
|
|
@@ -155,6 +156,11 @@ module.exports = function createQueue({ file, store, onJob, options = {} }) {
|
|
|
155
156
|
|
|
156
157
|
try {
|
|
157
158
|
const doc = await store.getJob(id);
|
|
159
|
+
if (!doc) {
|
|
160
|
+
emit('failed', { id, job, error: err });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
158
164
|
if (doc.retryCount >= maxRetries) {
|
|
159
165
|
logger.info('fail job', { id });
|
|
160
166
|
await clearJob(id);
|
|
@@ -183,7 +189,12 @@ module.exports = function createQueue({ file, store, onJob, options = {} }) {
|
|
|
183
189
|
});
|
|
184
190
|
|
|
185
191
|
if (persist) {
|
|
186
|
-
store
|
|
192
|
+
store
|
|
193
|
+
.addJob(id, job)
|
|
194
|
+
.then(queueJob)
|
|
195
|
+
.catch((err) => {
|
|
196
|
+
logger.error('Can not add job to store', { error: err });
|
|
197
|
+
});
|
|
187
198
|
} else {
|
|
188
199
|
queueJob();
|
|
189
200
|
}
|
|
@@ -255,6 +266,10 @@ module.exports = function createQueue({ file, store, onJob, options = {} }) {
|
|
|
255
266
|
return Object.assign(queueEvents, {
|
|
256
267
|
store,
|
|
257
268
|
push,
|
|
269
|
+
drain: (cb) => (queue.drain = cb),
|
|
270
|
+
empty: (cb) => (queue.empty = cb),
|
|
271
|
+
saturated: (cb) => (queue.saturated = cb),
|
|
272
|
+
error: (cb) => (queue.error = cb),
|
|
258
273
|
get: getJob,
|
|
259
274
|
cancel,
|
|
260
275
|
options: {
|
package/lib/store/nedb.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
/* eslint-disable func-names */
|
|
3
3
|
/* eslint-disable consistent-return */
|
|
4
|
+
const CustomError = require('@abtnode/util/lib/custom-error');
|
|
4
5
|
const { DataStore } = require('@abtnode/db/lib/base');
|
|
5
6
|
|
|
6
7
|
class NedbStore {
|
|
@@ -38,7 +39,7 @@ class NedbStore {
|
|
|
38
39
|
async updateJob(id, updates) {
|
|
39
40
|
const job = await this.db.findOne({ id });
|
|
40
41
|
if (!job) {
|
|
41
|
-
throw new
|
|
42
|
+
throw new CustomError('JOB_NOT_FOUND', `Job ${id} does not exist`);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const update = { ...updates, updatedAt: Date.now() };
|
|
@@ -49,7 +50,7 @@ class NedbStore {
|
|
|
49
50
|
async addJob(id, job, attrs = {}) {
|
|
50
51
|
const exist = await this.db.findOne({ id });
|
|
51
52
|
if (exist) {
|
|
52
|
-
throw new
|
|
53
|
+
throw new CustomError('JOB_DUPLICATE', `Job ${id} already exist`);
|
|
53
54
|
}
|
|
54
55
|
return this.db.insert({
|
|
55
56
|
id,
|
package/lib/store/sequelize.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const CustomError = require('@abtnode/util/lib/custom-error');
|
|
2
|
+
|
|
1
3
|
class SequelizeStore {
|
|
2
4
|
constructor(db, queue) {
|
|
3
5
|
this.db = db;
|
|
@@ -28,7 +30,7 @@ class SequelizeStore {
|
|
|
28
30
|
async updateJob(id, updates) {
|
|
29
31
|
const job = await this.db.findOne({ queue: this.queue, id });
|
|
30
32
|
if (!job) {
|
|
31
|
-
throw new
|
|
33
|
+
throw new CustomError('JOB_NOT_FOUND', `Job ${id} does not exist`);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const update = { ...updates, updatedAt: Date.now() };
|
|
@@ -39,7 +41,7 @@ class SequelizeStore {
|
|
|
39
41
|
async addJob(id, job, attrs = {}) {
|
|
40
42
|
const exist = await this.db.findOne({ queue: this.queue, id });
|
|
41
43
|
if (exist) {
|
|
42
|
-
throw new
|
|
44
|
+
throw new CustomError('JOB_DUPLICATE', `Job ${id} already exist`);
|
|
43
45
|
}
|
|
44
46
|
return this.db.insert({
|
|
45
47
|
id,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.11-next-
|
|
6
|
+
"version": "1.16.11-next-9f5464a1",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/db": "1.16.11-next-
|
|
23
|
-
"@abtnode/util": "1.16.11-next-
|
|
22
|
+
"@abtnode/db": "1.16.11-next-9f5464a1",
|
|
23
|
+
"@abtnode/util": "1.16.11-next-9f5464a1",
|
|
24
24
|
"debug": "^4.3.4",
|
|
25
25
|
"fastq": "^1.13.0",
|
|
26
26
|
"uuid": "^8.3.2"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "8f29a3c9889c23938a75a56c682e892f04088e19",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"jest": "^27.5.1"
|
|
31
31
|
}
|