power-queues 0.0.14 → 1.0.0
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/dist/Processor.d.ts +14 -0
- package/dist/Processor.js +47 -0
- package/dist/Processor.js.map +1 -0
- package/dist/Queue.d.ts +30 -0
- package/dist/Queue.js +149 -0
- package/dist/Queue.js.map +1 -0
- package/dist/QueuePortion.d.ts +8 -0
- package/dist/QueuePortion.js +35 -0
- package/dist/QueuePortion.js.map +1 -0
- package/dist/QueuePortionProcessor.d.ts +8 -0
- package/dist/QueuePortionProcessor.js +41 -0
- package/dist/QueuePortionProcessor.js.map +1 -0
- package/dist/QueuePortionProcessorMethod.d.ts +11 -0
- package/dist/QueuePortionProcessorMethod.js +68 -0
- package/dist/QueuePortionProcessorMethod.js.map +1 -0
- package/dist/QueueProcessor.d.ts +14 -0
- package/dist/QueueProcessor.js +55 -0
- package/dist/QueueProcessor.js.map +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/ProcessorService.d.ts +0 -7
- package/dist/ProcessorService.js +0 -19
- package/dist/ProcessorService.js.map +0 -1
- package/dist/QueuePortionProcessorOrderService.d.ts +0 -5
- package/dist/QueuePortionProcessorOrderService.js +0 -44
- package/dist/QueuePortionProcessorOrderService.js.map +0 -1
- package/dist/QueuePortionProcessorService.d.ts +0 -8
- package/dist/QueuePortionProcessorService.js +0 -26
- package/dist/QueuePortionProcessorService.js.map +0 -1
- package/dist/QueuePortionService.d.ts +0 -7
- package/dist/QueuePortionService.js +0 -38
- package/dist/QueuePortionService.js.map +0 -1
- package/dist/QueueProcessorService.d.ts +0 -15
- package/dist/QueueProcessorService.js +0 -66
- package/dist/QueueProcessorService.js.map +0 -1
- package/dist/QueueService.d.ts +0 -18
- package/dist/QueueService.js +0 -86
- package/dist/QueueService.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class Processor {
|
|
2
|
+
readonly defaultName: string;
|
|
3
|
+
get name(): string;
|
|
4
|
+
excecute(queueName: string, attemptIndex: number, data: any): Promise<any>;
|
|
5
|
+
success(data: any): Promise<any>;
|
|
6
|
+
successMethod(data: any): Promise<any>;
|
|
7
|
+
timestamp(date?: Date): string;
|
|
8
|
+
orderMethods(): Array<Function>;
|
|
9
|
+
errorMethods(): Array<Function>;
|
|
10
|
+
getMethods(): Array<Function>;
|
|
11
|
+
getMethodsLength(): number;
|
|
12
|
+
getMethod(index: number): Function;
|
|
13
|
+
isErrorMethod(method: Function): boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Processor = void 0;
|
|
4
|
+
class Processor {
|
|
5
|
+
get name() {
|
|
6
|
+
return this.defaultName ?? this.constructor.name;
|
|
7
|
+
}
|
|
8
|
+
async excecute(queueName, attemptIndex, data) {
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
async success(data) {
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
async successMethod(data) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
timestamp(date = new Date()) {
|
|
18
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
19
|
+
const year = date.getFullYear();
|
|
20
|
+
const month = pad(date.getMonth() + 1);
|
|
21
|
+
const day = pad(date.getDate());
|
|
22
|
+
const hours = pad(date.getHours());
|
|
23
|
+
const minutes = pad(date.getMinutes());
|
|
24
|
+
const seconds = pad(date.getSeconds());
|
|
25
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
26
|
+
}
|
|
27
|
+
orderMethods() {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
errorMethods() {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
getMethods() {
|
|
34
|
+
return [...this.orderMethods()];
|
|
35
|
+
}
|
|
36
|
+
getMethodsLength() {
|
|
37
|
+
return this.orderMethods().length;
|
|
38
|
+
}
|
|
39
|
+
getMethod(index) {
|
|
40
|
+
return this.orderMethods()[index];
|
|
41
|
+
}
|
|
42
|
+
isErrorMethod(method) {
|
|
43
|
+
return !!this.errorMethods().find((item) => item.name === method.name);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.Processor = Processor;
|
|
47
|
+
//# sourceMappingURL=Processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Processor.js","sourceRoot":"","sources":["../src/Processor.ts"],"names":[],"mappings":";;;AACA,MAAa,SAAS;IAGrB,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAS;QAChE,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAS;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAAS;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,SAAS,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE;QAC1B,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAEtD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAEhC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAEvC,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;IACjE,CAAC;IAED,YAAY;QACX,OAAO,EAAE,CAAC;IACX,CAAC;IAED,YAAY;QACX,OAAO,EAAE,CAAC;IACX,CAAC;IAED,UAAU;QACT,OAAO,CAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAE,CAAC;IACnC,CAAC;IAED,gBAAgB;QACf,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC;IACnC,CAAC;IAED,SAAS,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,aAAa,CAAC,MAAgB;QAC7B,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;CACD;AAxDD,8BAwDC"}
|
package/dist/Queue.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
export declare class Queue {
|
|
3
|
+
protected readonly redis: Redis | null;
|
|
4
|
+
protected readonly threadId: string;
|
|
5
|
+
protected readonly timeout: number;
|
|
6
|
+
protected readonly attempts: number;
|
|
7
|
+
protected readonly displayError: boolean;
|
|
8
|
+
protected readonly displayErrorInst: boolean;
|
|
9
|
+
protected readonly displayErrorData: boolean;
|
|
10
|
+
timestamp(date?: Date): string;
|
|
11
|
+
queueKey(queueName: string, attemptIndex: number): string;
|
|
12
|
+
readyKey(queueName: string, attemptIndex: number): string;
|
|
13
|
+
start(queueName: string): void;
|
|
14
|
+
listen(queueName: string): void;
|
|
15
|
+
wait(): Promise<void>;
|
|
16
|
+
attempt(queueName: string, attemptIndex: number): Promise<void>;
|
|
17
|
+
process(queueName: string, attemptIndex: number): Promise<void>;
|
|
18
|
+
processOne(queueName: string, attemptIndex: number): Promise<void>;
|
|
19
|
+
retry(queueName: string, attemptIndex: number, data: any, err: any): Promise<number>;
|
|
20
|
+
select(queueName: string, attemptIndex: number): Promise<any>;
|
|
21
|
+
selectAfter(data: any): Promise<any>;
|
|
22
|
+
allow(queueName: string, attemptIndex: number, data: any): Promise<boolean>;
|
|
23
|
+
excecuteWrapper(queueName: string, attemptIndex: number, data: any): Promise<any>;
|
|
24
|
+
excecute(queueName: string, attemptIndex: number, data: any): Promise<any>;
|
|
25
|
+
successWrapper(queueName: string, attemptIndex: number, data: any): Promise<void>;
|
|
26
|
+
success(queueName: string, attemptIndex: number, data: any): Promise<void>;
|
|
27
|
+
errorWrapper(queueName: string, attemptIndex: number, data: any, err: any): Promise<void>;
|
|
28
|
+
errorMessage(queueName: string, attemptIndex: number, data: any, err: any): Promise<void>;
|
|
29
|
+
error(queueName: string, attemptIndex: number, data: any, err: any): Promise<void>;
|
|
30
|
+
}
|
package/dist/Queue.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class Queue {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.threadId = (0, uuid_1.v4)();
|
|
8
|
+
this.timeout = 10;
|
|
9
|
+
this.attempts = 1;
|
|
10
|
+
this.displayError = true;
|
|
11
|
+
this.displayErrorInst = true;
|
|
12
|
+
this.displayErrorData = true;
|
|
13
|
+
}
|
|
14
|
+
timestamp(date = new Date()) {
|
|
15
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
16
|
+
const year = date.getFullYear();
|
|
17
|
+
const month = pad(date.getMonth() + 1);
|
|
18
|
+
const day = pad(date.getDate());
|
|
19
|
+
const hours = pad(date.getHours());
|
|
20
|
+
const minutes = pad(date.getMinutes());
|
|
21
|
+
const seconds = pad(date.getSeconds());
|
|
22
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
23
|
+
}
|
|
24
|
+
queueKey(queueName, attemptIndex) {
|
|
25
|
+
return `queue.${queueName}.${attemptIndex}`;
|
|
26
|
+
}
|
|
27
|
+
readyKey(queueName, attemptIndex) {
|
|
28
|
+
return `ready.${queueName}.${attemptIndex}`;
|
|
29
|
+
}
|
|
30
|
+
start(queueName) {
|
|
31
|
+
this.listen(queueName);
|
|
32
|
+
}
|
|
33
|
+
listen(queueName) {
|
|
34
|
+
let i = 0;
|
|
35
|
+
while (i < this.attempts) {
|
|
36
|
+
this.attempt(queueName, i);
|
|
37
|
+
i++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async wait() {
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, this.timeout));
|
|
42
|
+
}
|
|
43
|
+
async attempt(queueName, attemptIndex) {
|
|
44
|
+
const readyKey = this.readyKey(queueName, attemptIndex);
|
|
45
|
+
const threadId = this.threadId;
|
|
46
|
+
await this.redis.rpush(readyKey, this.threadId);
|
|
47
|
+
await this.wait();
|
|
48
|
+
setImmediate(() => this.process(queueName, attemptIndex));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
async process(queueName, attemptIndex) {
|
|
52
|
+
try {
|
|
53
|
+
await this.processOne(queueName, attemptIndex);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
await this.errorWrapper(queueName, attemptIndex, null, err);
|
|
57
|
+
}
|
|
58
|
+
await this.wait();
|
|
59
|
+
setImmediate(() => this.process(queueName, attemptIndex));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
async processOne(queueName, attemptIndex) {
|
|
63
|
+
const readyKey = this.readyKey(queueName, attemptIndex);
|
|
64
|
+
const readyThreadId = await this.redis.lpop(readyKey);
|
|
65
|
+
if (readyThreadId) {
|
|
66
|
+
if (readyThreadId === this.threadId) {
|
|
67
|
+
const data = await this.select(queueName, attemptIndex);
|
|
68
|
+
const allow = await this.allow(queueName, attemptIndex, data);
|
|
69
|
+
if (allow) {
|
|
70
|
+
try {
|
|
71
|
+
await this.successWrapper(queueName, attemptIndex, await this.excecute(queueName, attemptIndex, data));
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.retry(queueName, attemptIndex, data, err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
await this.redis.rpush(readyKey, readyThreadId);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async retry(queueName, attemptIndex, data, err) {
|
|
82
|
+
try {
|
|
83
|
+
if (attemptIndex < (this.attempts - 1)) {
|
|
84
|
+
const queueKey = this.queueKey(queueName, attemptIndex);
|
|
85
|
+
const dataProcessed = JSON.stringify(data);
|
|
86
|
+
return await this.redis.rpush(queueKey, dataProcessed);
|
|
87
|
+
}
|
|
88
|
+
await this.errorWrapper(queueName, attemptIndex, data, err);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
async select(queueName, attemptIndex) {
|
|
95
|
+
const queueKey = this.queueKey(queueName, attemptIndex);
|
|
96
|
+
const data = await this.redis.lpop(queueKey);
|
|
97
|
+
return await this.selectAfter(data);
|
|
98
|
+
}
|
|
99
|
+
async selectAfter(data) {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(data);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
async allow(queueName, attemptIndex, data) {
|
|
108
|
+
return !!data;
|
|
109
|
+
}
|
|
110
|
+
async excecuteWrapper(queueName, attemptIndex, data) {
|
|
111
|
+
await this.excecute(queueName, attemptIndex, data);
|
|
112
|
+
}
|
|
113
|
+
async excecute(queueName, attemptIndex, data) {
|
|
114
|
+
return await this.successWrapper(queueName, attemptIndex, data);
|
|
115
|
+
}
|
|
116
|
+
async successWrapper(queueName, attemptIndex, data) {
|
|
117
|
+
await this.success(queueName, attemptIndex, data);
|
|
118
|
+
}
|
|
119
|
+
async success(queueName, attemptIndex, data) {
|
|
120
|
+
}
|
|
121
|
+
async errorWrapper(queueName, attemptIndex, data, err) {
|
|
122
|
+
try {
|
|
123
|
+
await this.error(queueName, attemptIndex, data, err);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
await this.errorMessage(queueName, attemptIndex, data, err);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async errorMessage(queueName, attemptIndex, data, err) {
|
|
130
|
+
if (this.displayError) {
|
|
131
|
+
console.log(`\n-------------------------------------`);
|
|
132
|
+
console.error(`[ERR]`, this.timestamp());
|
|
133
|
+
console.error(` `, `Очередь:`, queueName);
|
|
134
|
+
console.error(` `, `Попытка:`, attemptIndex);
|
|
135
|
+
console.error(` `, `Результат:`, typeof data);
|
|
136
|
+
console.error(` `, `Сообщение:`, err.message);
|
|
137
|
+
if (this.displayErrorInst) {
|
|
138
|
+
console.error(` `, `Ошибка:`, err);
|
|
139
|
+
}
|
|
140
|
+
if (this.displayErrorData) {
|
|
141
|
+
console.error(` `, `Данные:`, data);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async error(queueName, attemptIndex, data, err) {
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.Queue = Queue;
|
|
149
|
+
//# sourceMappingURL=Queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAEpC,MAAa,KAAK;IAAlB;Q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C;YACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC3B,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;IACF,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAS,EAAE,GAAG;IACnE,CAAC;CACD;AA7KD,sBA6KC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Queue } from './Queue';
|
|
2
|
+
export declare class QueuePortion extends Queue {
|
|
3
|
+
protected readonly portionSize: number;
|
|
4
|
+
allow(queueName: string, attemptIndex: number, data: Array<any>): Promise<boolean>;
|
|
5
|
+
select(queueName: string, attemptIndex: number): Promise<Array<any>>;
|
|
6
|
+
selectAfter(data: Array<any>): Promise<Array<any>>;
|
|
7
|
+
excecuteWrapper(queueName: string, attemptIndex: number, data: Array<any>): Promise<Array<any>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueuePortion = void 0;
|
|
4
|
+
const Queue_1 = require("./Queue");
|
|
5
|
+
class QueuePortion extends Queue_1.Queue {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.portionSize = 1;
|
|
9
|
+
}
|
|
10
|
+
async allow(queueName, attemptIndex, data) {
|
|
11
|
+
return data.length > 0 && data.filter((item) => !!item).length === data.length;
|
|
12
|
+
}
|
|
13
|
+
async select(queueName, attemptIndex) {
|
|
14
|
+
const queueKey = this.queueKey(queueName, attemptIndex);
|
|
15
|
+
const data = await this.redis.lpop(queueKey, this.portionSize);
|
|
16
|
+
return await this.selectAfter(data);
|
|
17
|
+
}
|
|
18
|
+
async selectAfter(data) {
|
|
19
|
+
let i = 0, output = [];
|
|
20
|
+
while (i < data.length) {
|
|
21
|
+
output.push(await super.selectAfter(data));
|
|
22
|
+
}
|
|
23
|
+
return output;
|
|
24
|
+
}
|
|
25
|
+
async excecuteWrapper(queueName, attemptIndex, data) {
|
|
26
|
+
let i = 0, output = [];
|
|
27
|
+
while (i < data.length) {
|
|
28
|
+
output.push(await this.successWrapper(queueName, attemptIndex, await this.excecute(queueName, attemptIndex, data[i])));
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
return output;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.QueuePortion = QueuePortion;
|
|
35
|
+
//# sourceMappingURL=QueuePortion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueuePortion.js","sourceRoot":"","sources":["../src/QueuePortion.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAEjC,MAAa,YAAa,SAAQ,aAAK;IAAvC;;QACoB,gBAAW,GAAW,CAAC,CAAC;IAiC5C,CAAC;IA/BA,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAgB;QACpE,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,SAAiB,EAAE,YAAoB;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAE/D,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAgB;QACjC,IAAI,CAAC,GAAG,CAAC,EACR,MAAM,GAAG,EAAE,CAAC;QAEb,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAgB;QAC9E,IAAI,CAAC,GAAG,CAAC,EACR,MAAM,GAAG,EAAE,CAAC;QAEb,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvH,CAAC,EAAE,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAlCD,oCAkCC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QueueProcessor } from './QueueProcessor';
|
|
2
|
+
export declare class QueuePortionProcessor extends QueueProcessor {
|
|
3
|
+
protected readonly portionSize: number;
|
|
4
|
+
allow(queueName: string, attemptIndex: number, data: Array<any>): Promise<boolean>;
|
|
5
|
+
select(queueName: string, attemptIndex: number): Promise<Array<any>>;
|
|
6
|
+
selectAfter(data: Array<any>): Promise<Array<any>>;
|
|
7
|
+
excecuteWrapper(queueName: string, attemptIndex: number, data: Array<any>): Promise<Array<any>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueuePortionProcessor = void 0;
|
|
4
|
+
const QueueProcessor_1 = require("./QueueProcessor");
|
|
5
|
+
class QueuePortionProcessor extends QueueProcessor_1.QueueProcessor {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.portionSize = 1;
|
|
9
|
+
}
|
|
10
|
+
async allow(queueName, attemptIndex, data) {
|
|
11
|
+
return data.length > 0 && data.filter((item) => !!item).length === data.length;
|
|
12
|
+
}
|
|
13
|
+
async select(queueName, attemptIndex) {
|
|
14
|
+
const queueKey = this.queueKey(queueName, attemptIndex);
|
|
15
|
+
const data = await this.redis.lpop(queueKey, this.portionSize);
|
|
16
|
+
return await this.selectAfter(data);
|
|
17
|
+
}
|
|
18
|
+
async selectAfter(data) {
|
|
19
|
+
let i = 0, output = [];
|
|
20
|
+
while (i < data.length) {
|
|
21
|
+
output.push(await super.selectAfter(data));
|
|
22
|
+
}
|
|
23
|
+
return output;
|
|
24
|
+
}
|
|
25
|
+
async excecuteWrapper(queueName, attemptIndex, data) {
|
|
26
|
+
const keyData = this.keyData(queueName);
|
|
27
|
+
const processorName = keyData.processorName;
|
|
28
|
+
const processor = this.getProcessorByName(processorName);
|
|
29
|
+
if (!processor || !processor.excecute) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let i = 0, output = [];
|
|
33
|
+
while (i < data.length) {
|
|
34
|
+
output.push(await this.successWrapper(queueName, attemptIndex, await this.excecute(queueName, attemptIndex, await processor.excecute.call(processor, attemptIndex, data[i]))));
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
return output;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.QueuePortionProcessor = QueuePortionProcessor;
|
|
41
|
+
//# sourceMappingURL=QueuePortionProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueuePortionProcessor.js","sourceRoot":"","sources":["../src/QueuePortionProcessor.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAGnD,MAAa,qBAAsB,SAAQ,+BAAc;IAAzD;;QACoB,gBAAW,GAAW,CAAC,CAAC;IAwC5C,CAAC;IAtCA,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,YAAoB,EAAE,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YACxB,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/K,CAAC,EAAE,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAzCD,sDAyCC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { QueuePortionProcessor } from './QueuePortionProcessor';
|
|
2
|
+
export declare class QueuePortionProcessorMethod extends QueuePortionProcessor {
|
|
3
|
+
keyData(queueName: string): {
|
|
4
|
+
processorName: string;
|
|
5
|
+
methodIndex: number;
|
|
6
|
+
};
|
|
7
|
+
start(queueName: string): void;
|
|
8
|
+
successWrapper(queueName: string, attemptIndex: number, data: any): Promise<void>;
|
|
9
|
+
successMethod(queueName: string, attemptIndex: number, data: any): Promise<void>;
|
|
10
|
+
errorWrapper(queueName: string, attemptIndex: number, data: any, err: any): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueuePortionProcessorMethod = void 0;
|
|
4
|
+
const QueuePortionProcessor_1 = require("./QueuePortionProcessor");
|
|
5
|
+
class QueuePortionProcessorMethod extends QueuePortionProcessor_1.QueuePortionProcessor {
|
|
6
|
+
keyData(queueName) {
|
|
7
|
+
const queueNameSplit = queueName.split(`.`);
|
|
8
|
+
const processorName = queueNameSplit[queueNameSplit.length - 2];
|
|
9
|
+
const methodIndex = Number(queueNameSplit[queueNameSplit.length - 1]);
|
|
10
|
+
return {
|
|
11
|
+
processorName,
|
|
12
|
+
methodIndex,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
start(queueName) {
|
|
16
|
+
const processors = this.getProcessors();
|
|
17
|
+
let i = 0;
|
|
18
|
+
while (i < processors.length) {
|
|
19
|
+
const processor = processors[i];
|
|
20
|
+
const methods = processor.getMethods();
|
|
21
|
+
let ii = 0;
|
|
22
|
+
while (ii < methods.length) {
|
|
23
|
+
this.listen(`${queueName}.${processor.name}.${ii}`);
|
|
24
|
+
ii++;
|
|
25
|
+
}
|
|
26
|
+
i++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async successWrapper(queueName, attemptIndex, data) {
|
|
30
|
+
const keyData = this.keyData(queueName);
|
|
31
|
+
const processorName = keyData.processorName;
|
|
32
|
+
const methodIndex = keyData.methodIndex;
|
|
33
|
+
const processor = this.getProcessorByName(processorName);
|
|
34
|
+
if (!processor) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const nextMethodIndex = methodIndex + 1;
|
|
38
|
+
const nextMethod = processor.getMethod(nextMethodIndex);
|
|
39
|
+
const methodsLength = processor.getMethodsLength();
|
|
40
|
+
if (nextMethod) {
|
|
41
|
+
const queueKey = await this.queueKey(`${queueName}.${nextMethodIndex}`, attemptIndex);
|
|
42
|
+
const dataProcessed = JSON.stringify(data);
|
|
43
|
+
await this.redis.rpush(queueKey, dataProcessed);
|
|
44
|
+
await this.successMethod(queueName, attemptIndex, data);
|
|
45
|
+
}
|
|
46
|
+
else if (nextMethodIndex === (methodsLength - 1)) {
|
|
47
|
+
await super.successWrapper(queueName, attemptIndex, data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async successMethod(queueName, attemptIndex, data) {
|
|
51
|
+
}
|
|
52
|
+
async errorWrapper(queueName, attemptIndex, data, err) {
|
|
53
|
+
const keyData = this.keyData(queueName);
|
|
54
|
+
const processorName = keyData.processorName;
|
|
55
|
+
const methodIndex = keyData.methodIndex;
|
|
56
|
+
const processor = this.getProcessorByName(processorName);
|
|
57
|
+
if (!processor) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const method = processor.getMethod(methodIndex);
|
|
61
|
+
const isErrorMethod = processor.isErrorMethod(method);
|
|
62
|
+
if (isErrorMethod) {
|
|
63
|
+
await super.errorWrapper(queueName, attemptIndex, data, err);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.QueuePortionProcessorMethod = QueuePortionProcessorMethod;
|
|
68
|
+
//# sourceMappingURL=QueuePortionProcessorMethod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueuePortionProcessorMethod.js","sourceRoot":"","sources":["../src/QueuePortionProcessorMethod.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAEhE,MAAa,2BAA4B,SAAQ,6CAAqB;IACrE,OAAO,CAAC,SAAiB;QACxB,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,aAAa,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAChE,MAAM,WAAW,GAAG,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAEtE,OAAO;YACN,aAAa;YACb,WAAW;SACX,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAiB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,OAAO,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,IAAI,EAAE,GAAG,CAAC,CAAC;YAEX,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,SAAS,CAAC,IAA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EAAE,IAAS;IACtE,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAS,EAAE,GAAG;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,OAAO;QACR,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAChD,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAEtD,IAAI,aAAa,EAAE,CAAC;YACnB,MAAM,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;CACD;AAzED,kEAyEC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Queue } from './Queue';
|
|
2
|
+
import { Processor } from './Processor';
|
|
3
|
+
export declare class QueueProcessor extends Queue {
|
|
4
|
+
private processors;
|
|
5
|
+
keyData(queueName: string): {
|
|
6
|
+
processorName: string;
|
|
7
|
+
};
|
|
8
|
+
setProcessors(processors: Array<Processor>): QueueProcessor;
|
|
9
|
+
getProcessors(): Array<Processor>;
|
|
10
|
+
getProcessorByName(name: string): Processor | null;
|
|
11
|
+
start(queueName: string): void;
|
|
12
|
+
excecuteWrapper(queueName: string, attemptIndex: number, data: any): Promise<any>;
|
|
13
|
+
listen(queueName: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueProcessor = void 0;
|
|
4
|
+
const Queue_1 = require("./Queue");
|
|
5
|
+
class QueueProcessor extends Queue_1.Queue {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.processors = [];
|
|
9
|
+
}
|
|
10
|
+
keyData(queueName) {
|
|
11
|
+
const queueNameSplit = queueName.split(`.`);
|
|
12
|
+
const processorName = queueNameSplit[queueNameSplit.length - 1];
|
|
13
|
+
return {
|
|
14
|
+
processorName,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
setProcessors(processors) {
|
|
18
|
+
this.processors = [...processors];
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
getProcessors() {
|
|
22
|
+
return [...this.processors];
|
|
23
|
+
}
|
|
24
|
+
getProcessorByName(name) {
|
|
25
|
+
return this.getProcessors().find((processor) => processor.name === name) ?? null;
|
|
26
|
+
}
|
|
27
|
+
start(queueName) {
|
|
28
|
+
const processors = this.getProcessors();
|
|
29
|
+
let i = 0;
|
|
30
|
+
while (i < processors.length) {
|
|
31
|
+
const processor = processors[i];
|
|
32
|
+
const queueKey = `${queueName}.${processor.name}`;
|
|
33
|
+
this.listen(queueKey);
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async excecuteWrapper(queueName, attemptIndex, data) {
|
|
38
|
+
const keyData = this.keyData(queueName);
|
|
39
|
+
const processorName = keyData.processorName;
|
|
40
|
+
const processor = this.getProcessorByName(processorName);
|
|
41
|
+
if (!processor || !processor.excecute) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return await this.successWrapper(queueName, attemptIndex, await this.excecute(queueName, attemptIndex, await processor.excecute.call(processor, attemptIndex, data)));
|
|
45
|
+
}
|
|
46
|
+
listen(queueName) {
|
|
47
|
+
let i = 0;
|
|
48
|
+
while (i < this.attempts) {
|
|
49
|
+
this.attempt(queueName, i);
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.QueueProcessor = QueueProcessor;
|
|
55
|
+
//# sourceMappingURL=QueueProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueueProcessor.js","sourceRoot":"","sources":["../src/QueueProcessor.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAGjC,MAAa,cAAe,SAAQ,aAAK;IAAzC;;QACS,eAAU,GAAqB,EAAE,CAAC;IAwD3C,CAAC;IAtDA,OAAO,CAAC,SAAiB;QACxB,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,aAAa,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEhE,OAAO;YACN,aAAa;SACb,CAAC;IACH,CAAC;IAED,aAAa,CAAC,UAA4B;QACzC,IAAI,CAAC,UAAU,GAAG,CAAE,GAAG,UAAU,CAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,aAAa;QACZ,OAAO,CAAE,GAAG,IAAI,CAAC,UAAU,CAAE,CAAC;IAC/B,CAAC;IAED,kBAAkB,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IAC7F,CAAC;IAED,KAAK,CAAC,SAAiB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,OAAO,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,QAAQ,GAAG,GAAG,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;YAElD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACtB,CAAC,EAAE,CAAC;QACL,CAAC;IACF,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAAoB,EAAE,IAAS;QACvE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACvC,OAAO;QACR,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvK,CAAC;IAED,MAAM,CAAC,SAAiB;QACvB,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC,EAAE,CAAC;QACL,CAAC;IACF,CAAC;CACD;AAzDD,wCAyDC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
1
|
+
import { QueuePortionProcessorMethod } from './QueuePortionProcessorMethod';
|
|
2
|
+
import { QueuePortionProcessor } from './QueuePortionProcessor';
|
|
3
|
+
import { QueuePortion } from './QueuePortion';
|
|
4
|
+
import { QueueProcessor } from './QueueProcessor';
|
|
5
|
+
import { Queue } from './Queue';
|
|
6
|
+
import { Processor } from './Processor';
|
|
7
|
+
export { QueuePortionProcessorMethod, QueuePortionProcessor, QueuePortion, QueueProcessor, Queue, Processor, };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
const
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
const
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
const
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
const
|
|
15
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.Processor = exports.Queue = exports.QueueProcessor = exports.QueuePortion = exports.QueuePortionProcessor = exports.QueuePortionProcessorMethod = void 0;
|
|
4
|
+
const QueuePortionProcessorMethod_1 = require("./QueuePortionProcessorMethod");
|
|
5
|
+
Object.defineProperty(exports, "QueuePortionProcessorMethod", { enumerable: true, get: function () { return QueuePortionProcessorMethod_1.QueuePortionProcessorMethod; } });
|
|
6
|
+
const QueuePortionProcessor_1 = require("./QueuePortionProcessor");
|
|
7
|
+
Object.defineProperty(exports, "QueuePortionProcessor", { enumerable: true, get: function () { return QueuePortionProcessor_1.QueuePortionProcessor; } });
|
|
8
|
+
const QueuePortion_1 = require("./QueuePortion");
|
|
9
|
+
Object.defineProperty(exports, "QueuePortion", { enumerable: true, get: function () { return QueuePortion_1.QueuePortion; } });
|
|
10
|
+
const QueueProcessor_1 = require("./QueueProcessor");
|
|
11
|
+
Object.defineProperty(exports, "QueueProcessor", { enumerable: true, get: function () { return QueueProcessor_1.QueueProcessor; } });
|
|
12
|
+
const Queue_1 = require("./Queue");
|
|
13
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return Queue_1.Queue; } });
|
|
14
|
+
const Processor_1 = require("./Processor");
|
|
15
|
+
Object.defineProperty(exports, "Processor", { enumerable: true, get: function () { return Processor_1.Processor; } });
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA4E;AAQ3E,4GARQ,yDAA2B,OAQR;AAP5B,mEAAgE;AAQ/D,sGARQ,6CAAqB,OAQR;AAPtB,iDAA8C;AAQ7C,6FARQ,2BAAY,OAQR;AAPb,qDAAkD;AAQjD,+FARQ,+BAAc,OAQR;AAPf,mCAAgC;AAQ/B,sFARQ,aAAK,OAQR;AAPN,2CAAwC;AAQvC,0FARQ,qBAAS,OAQR"}
|