exodus-framework 2.0.914 → 2.0.9151
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/services/task/queue/QueueService.d.ts +2 -0
- package/lib/services/task/queue/QueueService.d.ts.map +1 -1
- package/lib/services/task/queue/QueueService.js +3 -0
- package/lib/services/task/queue/SingleQueue.d.ts +22 -0
- package/lib/services/task/queue/SingleQueue.d.ts.map +1 -0
- package/lib/services/task/queue/SingleQueue.js +68 -0
- package/lib/services/task/queue/index.d.ts +1 -0
- package/lib/services/task/queue/index.d.ts.map +1 -1
- package/lib/services/task/queue/index.js +7 -0
- package/package.json +1 -1
@@ -1,9 +1,11 @@
|
|
1
|
+
import type { ConnectionOptions } from 'bullmq';
|
1
2
|
import TaskServiceBase from '../TaskServiceBase';
|
2
3
|
import QueueTask from './QueueTask';
|
3
4
|
declare class QueueTaskService extends TaskServiceBase<typeof QueueTask<any>> {
|
4
5
|
private connection;
|
5
6
|
onStart(): Promise<boolean>;
|
6
7
|
startTask(task: QueueTask<any>): Promise<void>;
|
8
|
+
getCacheConnection(): ConnectionOptions;
|
7
9
|
}
|
8
10
|
export default QueueTaskService;
|
9
11
|
//# sourceMappingURL=QueueService.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"QueueService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/QueueService.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"QueueService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/QueueService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAIhD,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,cAAM,gBAAiB,SAAQ,eAAe,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACnE,OAAO,CAAC,UAAU,CAAoB;IAEhC,OAAO;IAiBA,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC;IAwBpC,kBAAkB;CAG1B;AAED,eAAe,gBAAgB,CAAC"}
|
@@ -41,5 +41,8 @@ class QueueTaskService extends _TaskServiceBase.default {
|
|
41
41
|
task.setQueue(queue);
|
42
42
|
this.log(`Task '${task.getName()}' started...`, 'warning');
|
43
43
|
}
|
44
|
+
getCacheConnection() {
|
45
|
+
return this.connection;
|
46
|
+
}
|
44
47
|
}
|
45
48
|
var _default = exports.default = QueueTaskService;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Job, Queue, Worker } from 'bullmq';
|
2
|
+
import System from '../../../app/classes/system';
|
3
|
+
declare class SingleQueue<T = any, Result = any, Name extends string = any> extends System {
|
4
|
+
protected cacheKey: string;
|
5
|
+
protected worker: Worker;
|
6
|
+
protected queue: Queue;
|
7
|
+
protected concurrency: number;
|
8
|
+
protected name: string;
|
9
|
+
protected onTick: (data: T) => Promise<void>;
|
10
|
+
constructor(cacheKey: string);
|
11
|
+
start(): void;
|
12
|
+
private createQueue;
|
13
|
+
private createWorker;
|
14
|
+
setConcurrency(concurrency: number): void;
|
15
|
+
tick(job: Job<T, Result, Name>, _token: string): Promise<void>;
|
16
|
+
setTick(cb: (data: T) => Promise<void>): void;
|
17
|
+
addJob(data: T): Promise<void>;
|
18
|
+
pauseQueue(): void;
|
19
|
+
resumeQueue(): void;
|
20
|
+
}
|
21
|
+
export default SingleQueue;
|
22
|
+
//# sourceMappingURL=SingleQueue.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SingleQueue.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/SingleQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,MAAM,MAAM,6BAA6B,CAAC;AAIjD,cAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,SAAS,MAAM,GAAG,GAAG,CAAE,SAAQ,MAAM;IAOpE,SAAS,CAAC,QAAQ,EAAE,MAAM;IANtC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,WAAW,SAAK;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;gBAEvB,QAAQ,EAAE,MAAM;IAK/B,KAAK;IAKZ,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,YAAY;IAOb,cAAc,CAAC,WAAW,EAAE,MAAM;IAK5B,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM;IAOpD,OAAO,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;IAIhC,MAAM,CAAC,IAAI,EAAE,CAAC;IASpB,UAAU;IAKV,WAAW;CAInB;AAED,eAAe,WAAW,CAAC"}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _bullmq = require("bullmq");
|
8
|
+
var _system = _interopRequireDefault(require("../../../app/classes/system"));
|
9
|
+
var _QueueService = _interopRequireDefault(require("./QueueService"));
|
10
|
+
var _app = require("../../../app");
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
12
|
+
class SingleQueue extends _system.default {
|
13
|
+
worker;
|
14
|
+
queue;
|
15
|
+
concurrency = 1;
|
16
|
+
name;
|
17
|
+
onTick;
|
18
|
+
constructor(cacheKey) {
|
19
|
+
super();
|
20
|
+
this.cacheKey = cacheKey;
|
21
|
+
this.name = `${this.constructor.name}.${this.cacheKey}`;
|
22
|
+
}
|
23
|
+
start() {
|
24
|
+
this.createWorker();
|
25
|
+
this.createQueue();
|
26
|
+
}
|
27
|
+
createQueue() {
|
28
|
+
this.queue = new _bullmq.Queue(this.name, {
|
29
|
+
connection: _QueueService.default.getService().getCacheConnection()
|
30
|
+
});
|
31
|
+
}
|
32
|
+
createWorker() {
|
33
|
+
this.worker = new _bullmq.Worker(this.name, this.tick.bind(this), {
|
34
|
+
connection: _QueueService.default.getService().getCacheConnection(),
|
35
|
+
concurrency: this.concurrency
|
36
|
+
});
|
37
|
+
}
|
38
|
+
setConcurrency(concurrency) {
|
39
|
+
if (concurrency < 1) concurrency = 1;
|
40
|
+
this.concurrency = concurrency;
|
41
|
+
}
|
42
|
+
async tick(job, _token) {
|
43
|
+
if (!this.onTick) return;
|
44
|
+
const {
|
45
|
+
data
|
46
|
+
} = job;
|
47
|
+
await this.onTick(data);
|
48
|
+
}
|
49
|
+
setTick(cb) {
|
50
|
+
this.onTick = cb;
|
51
|
+
}
|
52
|
+
async addJob(data) {
|
53
|
+
if (!this.queue) {
|
54
|
+
new _app.ErrorHandler('falha ao adicionar uma tarefa', new Error('A task não está pronta'));
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
await this.queue.add(this.name, data);
|
58
|
+
}
|
59
|
+
pauseQueue() {
|
60
|
+
if (!this.queue) return;
|
61
|
+
this.queue.pause();
|
62
|
+
}
|
63
|
+
resumeQueue() {
|
64
|
+
if (!this.queue) return;
|
65
|
+
this.queue.resume();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
var _default = exports.default = SingleQueue;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
@@ -15,6 +15,13 @@ Object.defineProperty(exports, "QueueTaskService", {
|
|
15
15
|
return _QueueService.default;
|
16
16
|
}
|
17
17
|
});
|
18
|
+
Object.defineProperty(exports, "SingleQueue", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _SingleQueue.default;
|
22
|
+
}
|
23
|
+
});
|
18
24
|
var _QueueService = _interopRequireDefault(require("./QueueService"));
|
19
25
|
var _QueueTask = _interopRequireDefault(require("./QueueTask"));
|
26
|
+
var _SingleQueue = _interopRequireDefault(require("./SingleQueue"));
|
20
27
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|