@tsed/bullmq 7.38.0 → 7.38.1
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/coverage/clover.xml +0 -180
- package/coverage/coverage-final.json +0 -5
- package/coverage/coverage-summary.json +0 -6
- package/coverage/lcov-report/Job.ts.html +0 -136
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/decorators/Job.ts.html +0 -136
- package/coverage/lcov-report/decorators/index.html +0 -116
- package/coverage/lcov-report/dispatchers/JobDispatcher.ts.html +0 -148
- package/coverage/lcov-report/dispatchers/index.html +0 -116
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/BullMQModule.ts.html +0 -361
- package/coverage/lcov-report/src/config/config.ts.html +0 -142
- package/coverage/lcov-report/src/config/index.html +0 -116
- package/coverage/lcov-report/src/decorators/Job.ts.html +0 -136
- package/coverage/lcov-report/src/decorators/index.html +0 -116
- package/coverage/lcov-report/src/dispatchers/JobDispatcher.ts.html +0 -151
- package/coverage/lcov-report/src/dispatchers/index.html +0 -116
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/processors/ProcessorFactory.ts.html +0 -166
- package/coverage/lcov-report/src/processors/index.html +0 -116
- package/coverage/lcov.info +0 -245
- package/lib/cjs/decorators/Job.js +0 -17
- package/lib/cjs/decorators/Job.js.map +0 -1
- package/lib/cjs/processors/ProcessorFactory.js +0 -20
- package/lib/cjs/processors/ProcessorFactory.js.map +0 -1
- package/lib/types/decorators/Job.d.ts +0 -2
- package/lib/types/processors/ProcessorFactory.d.ts +0 -7
- package/src/BullMQModule.js +0 -149
- package/src/BullMQModule.spec.js +0 -236
- package/src/config/config.js +0 -2
- package/src/contracts/JobMethods.js +0 -2
- package/src/contracts/JobStore.js +0 -2
- package/src/contracts/index.js +0 -21
- package/src/decorators/Job.js +0 -18
- package/src/decorators/JobController.js +0 -18
- package/src/decorators/index.js +0 -20
- package/src/dispatchers/JobDispatcher.js +0 -72
- package/src/dispatchers/JobDispatcher.spec.js +0 -98
- package/src/dispatchers/index.js +0 -20
package/src/BullMQModule.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.BullMQModule = void 0;
|
|
46
|
-
var common_1 = require("@tsed/common");
|
|
47
|
-
var di_1 = require("@tsed/di");
|
|
48
|
-
var schema_1 = require("@tsed/schema");
|
|
49
|
-
var bullmq_1 = require("bullmq");
|
|
50
|
-
var uuid_1 = require("uuid");
|
|
51
|
-
var BullMQModule = /** @class */ (function () {
|
|
52
|
-
function BullMQModule(injector, dispatcher) {
|
|
53
|
-
this.injector = injector;
|
|
54
|
-
this.dispatcher = dispatcher;
|
|
55
|
-
}
|
|
56
|
-
BullMQModule.prototype.$beforeInit = function () {
|
|
57
|
-
var _this = this;
|
|
58
|
-
this.buildWorkers();
|
|
59
|
-
this.buildQueues();
|
|
60
|
-
this.injector.getMany("bullmq:cron").map(function (job) { return _this.dispatcher.dispatch((0, schema_1.getComputedType)(job)); });
|
|
61
|
-
};
|
|
62
|
-
BullMQModule.prototype.buildQueues = function () {
|
|
63
|
-
var _this = this;
|
|
64
|
-
this.bullmq.queues.forEach(function (queue) {
|
|
65
|
-
_this.injector
|
|
66
|
-
.add("bullmq.queue.".concat(queue), {
|
|
67
|
-
type: "bullmq:queue",
|
|
68
|
-
useValue: new bullmq_1.Queue(queue, {
|
|
69
|
-
connection: _this.bullmq.connection,
|
|
70
|
-
defaultJobOptions: _this.bullmq.defaultJobOptions
|
|
71
|
-
}),
|
|
72
|
-
hooks: {
|
|
73
|
-
$onDestroy: function (queue) { return queue.close(); }
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
.invoke("bullmq.queue.".concat(queue));
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
BullMQModule.prototype.buildWorkers = function () {
|
|
80
|
-
var _this = this;
|
|
81
|
-
var _a;
|
|
82
|
-
((_a = this.bullmq.workerQueues) !== null && _a !== void 0 ? _a : this.bullmq.queues).forEach(function (queue) {
|
|
83
|
-
_this.injector
|
|
84
|
-
.add("bullmq.worker.".concat(queue), {
|
|
85
|
-
type: "bullmq:worker",
|
|
86
|
-
useValue: new bullmq_1.Worker(queue, _this.onProcess.bind(_this), {
|
|
87
|
-
connection: _this.bullmq.connection
|
|
88
|
-
}),
|
|
89
|
-
hooks: {
|
|
90
|
-
$onDestroy: function (worker) { return worker.close(); }
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
.invoke("bullmq.worker.".concat(queue));
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
BullMQModule.prototype.getJob = function (name, queueName) {
|
|
97
|
-
return this.injector.get("bullmq.job.".concat(queueName, ".").concat(name));
|
|
98
|
-
};
|
|
99
|
-
BullMQModule.prototype.onProcess = function (job) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var jobService, $ctx, er_1;
|
|
102
|
-
return __generator(this, function (_a) {
|
|
103
|
-
switch (_a.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
jobService = this.getJob(job.name, job.queueName);
|
|
106
|
-
if (!jobService) {
|
|
107
|
-
this.injector.logger.warn({
|
|
108
|
-
event: "BULLMQ_JOB_NOT_FOUND",
|
|
109
|
-
message: "Job ".concat(job.name, " ").concat(job.queueName, " not found")
|
|
110
|
-
});
|
|
111
|
-
return [2 /*return*/];
|
|
112
|
-
}
|
|
113
|
-
$ctx = new common_1.DIContext({
|
|
114
|
-
injector: this.injector,
|
|
115
|
-
logger: this.injector.logger,
|
|
116
|
-
id: job.id || (0, uuid_1.v4)().split("-").join("")
|
|
117
|
-
});
|
|
118
|
-
$ctx.set("BULLMQ_JOB", job);
|
|
119
|
-
_a.label = 1;
|
|
120
|
-
case 1:
|
|
121
|
-
_a.trys.push([1, 3, 4, 6]);
|
|
122
|
-
return [4 /*yield*/, (0, common_1.runInContext)($ctx, function () { return jobService.handle(job.data, job); })];
|
|
123
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
124
|
-
case 3:
|
|
125
|
-
er_1 = _a.sent();
|
|
126
|
-
$ctx.logger.error({
|
|
127
|
-
event: "BULLMQ_JOB_ERROR",
|
|
128
|
-
message: er_1.message,
|
|
129
|
-
stack: er_1.stack
|
|
130
|
-
});
|
|
131
|
-
throw er_1;
|
|
132
|
-
case 4: return [4 /*yield*/, $ctx.destroy()];
|
|
133
|
-
case 5:
|
|
134
|
-
_a.sent();
|
|
135
|
-
return [7 /*endfinally*/];
|
|
136
|
-
case 6: return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
__decorate([
|
|
142
|
-
(0, di_1.Constant)("bullmq")
|
|
143
|
-
], BullMQModule.prototype, "bullmq", void 0);
|
|
144
|
-
BullMQModule = __decorate([
|
|
145
|
-
(0, di_1.Module)()
|
|
146
|
-
], BullMQModule);
|
|
147
|
-
return BullMQModule;
|
|
148
|
-
}());
|
|
149
|
-
exports.BullMQModule = BullMQModule;
|
package/src/BullMQModule.spec.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
var common_1 = require("@tsed/common");
|
|
46
|
-
var core_1 = require("@tsed/core");
|
|
47
|
-
var bullmq_1 = require("bullmq");
|
|
48
|
-
var ts_mockito_1 = require("ts-mockito");
|
|
49
|
-
require("./BullMQModule");
|
|
50
|
-
var BullMQModule_1 = require("./BullMQModule");
|
|
51
|
-
var decorators_1 = require("./decorators");
|
|
52
|
-
var dispatchers_1 = require("./dispatchers");
|
|
53
|
-
jest.mock("bullmq", function () {
|
|
54
|
-
return {
|
|
55
|
-
Queue: /** @class */ (function () {
|
|
56
|
-
function class_1(name) {
|
|
57
|
-
this.name = name;
|
|
58
|
-
}
|
|
59
|
-
class_1.prototype.close = function () { };
|
|
60
|
-
return class_1;
|
|
61
|
-
}()),
|
|
62
|
-
Worker: /** @class */ (function () {
|
|
63
|
-
function class_2(name) {
|
|
64
|
-
this.name = name;
|
|
65
|
-
}
|
|
66
|
-
class_2.prototype.close = function () { };
|
|
67
|
-
return class_2;
|
|
68
|
-
}())
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
var bullmq = {
|
|
72
|
-
queues: ["default", "foo", "bar"],
|
|
73
|
-
connection: {},
|
|
74
|
-
workerQueues: ["default", "foo"]
|
|
75
|
-
};
|
|
76
|
-
var CustomCronJob = /** @class */ (function () {
|
|
77
|
-
function CustomCronJob() {
|
|
78
|
-
}
|
|
79
|
-
CustomCronJob.prototype.handle = function () { };
|
|
80
|
-
CustomCronJob = __decorate([
|
|
81
|
-
(0, decorators_1.JobController)("cron", "default", {
|
|
82
|
-
repeat: {
|
|
83
|
-
pattern: "* * * * *"
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
], CustomCronJob);
|
|
87
|
-
return CustomCronJob;
|
|
88
|
-
}());
|
|
89
|
-
var RegularJob = /** @class */ (function () {
|
|
90
|
-
function RegularJob() {
|
|
91
|
-
}
|
|
92
|
-
RegularJob.prototype.handle = function () { };
|
|
93
|
-
RegularJob = __decorate([
|
|
94
|
-
(0, decorators_1.JobController)("regular", "default")
|
|
95
|
-
], RegularJob);
|
|
96
|
-
return RegularJob;
|
|
97
|
-
}());
|
|
98
|
-
describe("module", function () {
|
|
99
|
-
var dispatcher;
|
|
100
|
-
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
-
return __generator(this, function (_a) {
|
|
102
|
-
switch (_a.label) {
|
|
103
|
-
case 0:
|
|
104
|
-
dispatcher = (0, ts_mockito_1.mock)(dispatchers_1.JobDispatcher);
|
|
105
|
-
(0, ts_mockito_1.when)(dispatcher.dispatch(CustomCronJob)).thenResolve();
|
|
106
|
-
return [4 /*yield*/, common_1.PlatformTest.create({
|
|
107
|
-
bullmq: bullmq,
|
|
108
|
-
imports: [
|
|
109
|
-
{
|
|
110
|
-
token: dispatchers_1.JobDispatcher,
|
|
111
|
-
use: (0, ts_mockito_1.instance)(dispatcher)
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
})];
|
|
115
|
-
case 1:
|
|
116
|
-
_a.sent();
|
|
117
|
-
return [2 /*return*/];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}); });
|
|
121
|
-
beforeEach(function () { });
|
|
122
|
-
afterEach(common_1.PlatformTest.reset);
|
|
123
|
-
describe("cronjobs", function () {
|
|
124
|
-
it("should dispatch cron jobs", function () {
|
|
125
|
-
(0, ts_mockito_1.verify)(dispatcher.dispatch(CustomCronJob)).once();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe("queues", function () {
|
|
129
|
-
it("should get default", function () {
|
|
130
|
-
var instance = common_1.PlatformTest.get("bullmq.queue.default");
|
|
131
|
-
expect(instance).toBeInstanceOf(bullmq_1.Queue);
|
|
132
|
-
expect(instance.name).toBe("default");
|
|
133
|
-
});
|
|
134
|
-
it.each(bullmq.queues)("should register queue(%s)", function (queue) {
|
|
135
|
-
var instance = common_1.PlatformTest.get("bullmq.queue.".concat(queue));
|
|
136
|
-
expect(instance).toBeInstanceOf(bullmq_1.Queue);
|
|
137
|
-
expect(instance.name).toBe(queue);
|
|
138
|
-
});
|
|
139
|
-
it("should not allow direct injection of the queue", function () {
|
|
140
|
-
expect(common_1.PlatformTest.get(bullmq_1.Queue)).not.toBeInstanceOf(bullmq_1.Queue);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe("workers", function () {
|
|
144
|
-
it("should get default", function () {
|
|
145
|
-
var instance = common_1.PlatformTest.get("bullmq.worker.default");
|
|
146
|
-
expect(instance).toBeInstanceOf(bullmq_1.Worker);
|
|
147
|
-
expect(instance.name).toBe("default");
|
|
148
|
-
});
|
|
149
|
-
it.each(bullmq.workerQueues)("should register worker(%s)", function (queue) {
|
|
150
|
-
var instance = common_1.PlatformTest.get("bullmq.worker.".concat(queue));
|
|
151
|
-
expect(instance).toBeInstanceOf(bullmq_1.Worker);
|
|
152
|
-
expect(instance.name).toBe(queue);
|
|
153
|
-
});
|
|
154
|
-
it("should not register unspecified worker queue", function () {
|
|
155
|
-
expect(common_1.PlatformTest.get("bullmq.worker.bar")).toBeUndefined();
|
|
156
|
-
});
|
|
157
|
-
it("should not allow direct injection of the worker", function () {
|
|
158
|
-
expect(common_1.PlatformTest.get(bullmq_1.Worker)).not.toBeInstanceOf(bullmq_1.Worker);
|
|
159
|
-
});
|
|
160
|
-
it("should run worker and execute processor", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
161
|
-
var bullMQModule, worker, job;
|
|
162
|
-
return __generator(this, function (_a) {
|
|
163
|
-
switch (_a.label) {
|
|
164
|
-
case 0:
|
|
165
|
-
bullMQModule = common_1.PlatformTest.get(BullMQModule_1.BullMQModule);
|
|
166
|
-
worker = common_1.PlatformTest.get("bullmq.job.default.regular");
|
|
167
|
-
job = {
|
|
168
|
-
name: "regular",
|
|
169
|
-
queueName: "default",
|
|
170
|
-
data: { test: "test" }
|
|
171
|
-
};
|
|
172
|
-
jest.spyOn(worker, "handle").mockResolvedValueOnce(undefined);
|
|
173
|
-
return [4 /*yield*/, bullMQModule.onProcess(job)];
|
|
174
|
-
case 1:
|
|
175
|
-
_a.sent();
|
|
176
|
-
expect(worker.handle).toHaveBeenCalledWith({ test: "test" }, job);
|
|
177
|
-
return [2 /*return*/];
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}); });
|
|
181
|
-
it("should log warning when the worker doesn't exists", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
182
|
-
var bullMQModule, job;
|
|
183
|
-
return __generator(this, function (_a) {
|
|
184
|
-
switch (_a.label) {
|
|
185
|
-
case 0:
|
|
186
|
-
bullMQModule = common_1.PlatformTest.get(BullMQModule_1.BullMQModule);
|
|
187
|
-
jest.spyOn(common_1.PlatformTest.injector.logger, "warn");
|
|
188
|
-
job = {
|
|
189
|
-
name: "regular",
|
|
190
|
-
queueName: "toto",
|
|
191
|
-
data: { test: "test" }
|
|
192
|
-
};
|
|
193
|
-
return [4 /*yield*/, bullMQModule.onProcess(job)];
|
|
194
|
-
case 1:
|
|
195
|
-
_a.sent();
|
|
196
|
-
expect(common_1.PlatformTest.injector.logger.warn).toHaveBeenCalledWith({
|
|
197
|
-
event: "BULLMQ_JOB_NOT_FOUND",
|
|
198
|
-
message: "Job regular toto not found"
|
|
199
|
-
});
|
|
200
|
-
return [2 /*return*/];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}); });
|
|
204
|
-
it("should run worker, execute processor and handle error", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
-
var bullMQModule, worker, job, error;
|
|
206
|
-
return __generator(this, function (_a) {
|
|
207
|
-
switch (_a.label) {
|
|
208
|
-
case 0:
|
|
209
|
-
bullMQModule = common_1.PlatformTest.get(BullMQModule_1.BullMQModule);
|
|
210
|
-
worker = common_1.PlatformTest.get("bullmq.job.default.regular");
|
|
211
|
-
job = {
|
|
212
|
-
name: "regular",
|
|
213
|
-
queueName: "default",
|
|
214
|
-
data: { test: "test" }
|
|
215
|
-
};
|
|
216
|
-
jest.spyOn(common_1.PlatformTest.injector.logger, "error");
|
|
217
|
-
jest.spyOn(worker, "handle").mockRejectedValue(new Error("error"));
|
|
218
|
-
return [4 /*yield*/, (0, core_1.catchAsyncError)(function () { return bullMQModule.onProcess(job); })];
|
|
219
|
-
case 1:
|
|
220
|
-
error = _a.sent();
|
|
221
|
-
expect(worker.handle).toHaveBeenCalledWith({ test: "test" }, job);
|
|
222
|
-
expect(common_1.PlatformTest.injector.logger.error).toHaveBeenCalledWith({
|
|
223
|
-
duration: expect.any(Number),
|
|
224
|
-
event: "BULLMQ_JOB_ERROR",
|
|
225
|
-
message: "error",
|
|
226
|
-
reqId: expect.any(String),
|
|
227
|
-
stack: expect.any(String),
|
|
228
|
-
time: expect.any(Object)
|
|
229
|
-
});
|
|
230
|
-
expect(error === null || error === void 0 ? void 0 : error.message).toEqual("error");
|
|
231
|
-
return [2 /*return*/];
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}); });
|
|
235
|
-
});
|
|
236
|
-
});
|
package/src/config/config.js
DELETED
package/src/contracts/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file Automatically generated by barrelsby.
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./JobMethods"), exports);
|
|
21
|
-
__exportStar(require("./JobStore"), exports);
|
package/src/decorators/Job.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Job = void 0;
|
|
4
|
-
var core_1 = require("@tsed/core");
|
|
5
|
-
var di_1 = require("@tsed/di");
|
|
6
|
-
function Job(name, queue, opts) {
|
|
7
|
-
if (queue === void 0) { queue = "default"; }
|
|
8
|
-
if (opts === void 0) { opts = {}; }
|
|
9
|
-
return (0, core_1.useDecorators)((0, core_1.StoreMerge)("bullmq", {
|
|
10
|
-
name: name,
|
|
11
|
-
queue: queue,
|
|
12
|
-
opts: opts
|
|
13
|
-
}), (0, di_1.Injectable)({
|
|
14
|
-
provide: "bullmq.job.".concat(queue, ".").concat(name),
|
|
15
|
-
type: opts.repeat ? "bullmq:cron" : "bullmq:job"
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
exports.Job = Job;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JobController = void 0;
|
|
4
|
-
var core_1 = require("@tsed/core");
|
|
5
|
-
var di_1 = require("@tsed/di");
|
|
6
|
-
function JobController(name, queue, opts) {
|
|
7
|
-
if (queue === void 0) { queue = "default"; }
|
|
8
|
-
if (opts === void 0) { opts = {}; }
|
|
9
|
-
return (0, core_1.useDecorators)((0, core_1.StoreMerge)("bullmq", {
|
|
10
|
-
name: name,
|
|
11
|
-
queue: queue,
|
|
12
|
-
opts: opts
|
|
13
|
-
}), (0, di_1.Injectable)({
|
|
14
|
-
provide: "bullmq.job.".concat(queue, ".").concat(name),
|
|
15
|
-
type: opts.repeat ? "bullmq:cron" : "bullmq:job"
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
exports.JobController = JobController;
|
package/src/decorators/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file Automatically generated by barrelsby.
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./JobController"), exports);
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.JobDispatcher = void 0;
|
|
46
|
-
var di_1 = require("@tsed/di");
|
|
47
|
-
var core_1 = require("@tsed/core");
|
|
48
|
-
var JobDispatcher = /** @class */ (function () {
|
|
49
|
-
function JobDispatcher(injector) {
|
|
50
|
-
this.injector = injector;
|
|
51
|
-
}
|
|
52
|
-
// eslint-disable-next-line require-await
|
|
53
|
-
JobDispatcher.prototype.dispatch = function (job, payload) {
|
|
54
|
-
if (payload === void 0) { payload = {}; }
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var store, queue;
|
|
57
|
-
return __generator(this, function (_a) {
|
|
58
|
-
store = core_1.Store.from(job).get("bullmq");
|
|
59
|
-
queue = this.injector.getMany("bullmq:queue").find(function (queue) { return queue.name === store.queue; });
|
|
60
|
-
if (!queue) {
|
|
61
|
-
throw new Error("Queue(".concat(store.queue, ") not defined"));
|
|
62
|
-
}
|
|
63
|
-
return [2 /*return*/, queue.add(store.name, payload, store.opts)];
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
JobDispatcher = __decorate([
|
|
68
|
-
(0, di_1.Service)()
|
|
69
|
-
], JobDispatcher);
|
|
70
|
-
return JobDispatcher;
|
|
71
|
-
}());
|
|
72
|
-
exports.JobDispatcher = JobDispatcher;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
var di_1 = require("@tsed/di");
|
|
46
|
-
var JobDispatcher_1 = require("./JobDispatcher");
|
|
47
|
-
var decorators_1 = require("../decorators");
|
|
48
|
-
var bullmq_1 = require("bullmq");
|
|
49
|
-
var ts_mockito_1 = require("ts-mockito");
|
|
50
|
-
var ExampleTestJob = /** @class */ (function () {
|
|
51
|
-
function ExampleTestJob() {
|
|
52
|
-
}
|
|
53
|
-
ExampleTestJob.prototype.handle = function (payload) { };
|
|
54
|
-
ExampleTestJob = __decorate([
|
|
55
|
-
(0, decorators_1.JobController)("example-job", "default", {
|
|
56
|
-
backoff: 69
|
|
57
|
-
})
|
|
58
|
-
], ExampleTestJob);
|
|
59
|
-
return ExampleTestJob;
|
|
60
|
-
}());
|
|
61
|
-
var NotConfiguredQueueTestJob = /** @class */ (function () {
|
|
62
|
-
function NotConfiguredQueueTestJob() {
|
|
63
|
-
}
|
|
64
|
-
NotConfiguredQueueTestJob.prototype.handle = function () { };
|
|
65
|
-
NotConfiguredQueueTestJob = __decorate([
|
|
66
|
-
(0, decorators_1.JobController)("queue-not-configured", "not-configured")
|
|
67
|
-
], NotConfiguredQueueTestJob);
|
|
68
|
-
return NotConfiguredQueueTestJob;
|
|
69
|
-
}());
|
|
70
|
-
describe("JobDispatcher", function () {
|
|
71
|
-
it("should throw an exception when a queue is not configured", function () {
|
|
72
|
-
var injector = (0, ts_mockito_1.mock)(di_1.InjectorService);
|
|
73
|
-
(0, ts_mockito_1.when)(injector.getMany("bullmq:queue")).thenReturn([]);
|
|
74
|
-
var dispatcher = new JobDispatcher_1.JobDispatcher((0, ts_mockito_1.instance)(injector));
|
|
75
|
-
expect(dispatcher.dispatch(NotConfiguredQueueTestJob)).rejects.toThrow(new Error("Queue(not-configured) not defined"));
|
|
76
|
-
(0, ts_mockito_1.verify)(injector.getMany("bullmq:queue")).once();
|
|
77
|
-
});
|
|
78
|
-
it("should dispatch job", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
-
var injector, queue, dispatcher;
|
|
80
|
-
return __generator(this, function (_a) {
|
|
81
|
-
switch (_a.label) {
|
|
82
|
-
case 0:
|
|
83
|
-
injector = (0, ts_mockito_1.mock)(di_1.InjectorService);
|
|
84
|
-
queue = (0, ts_mockito_1.mock)(bullmq_1.Queue);
|
|
85
|
-
(0, ts_mockito_1.when)(queue.name).thenReturn("default");
|
|
86
|
-
(0, ts_mockito_1.when)(injector.getMany("bullmq:queue")).thenReturn([(0, ts_mockito_1.instance)(queue)]);
|
|
87
|
-
dispatcher = new JobDispatcher_1.JobDispatcher((0, ts_mockito_1.instance)(injector));
|
|
88
|
-
return [4 /*yield*/, dispatcher.dispatch(ExampleTestJob, { msg: "hello test" })];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.sent();
|
|
91
|
-
(0, ts_mockito_1.verify)(queue.add("example-job", (0, ts_mockito_1.objectContaining)({ msg: "hello test" }), (0, ts_mockito_1.objectContaining)({
|
|
92
|
-
backoff: 69
|
|
93
|
-
}))).once();
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}); });
|
|
98
|
-
});
|