@efebia/sqs-queue-v2 0.0.1 → 0.0.2
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.d.ts +2 -1
- package/lib/index.js +3 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import AWS from "aws-sdk";
|
|
|
3
3
|
import EventEmitter from "events";
|
|
4
4
|
export type QueueOptions = {
|
|
5
5
|
sleepTimeout: number;
|
|
6
|
+
errorCallback: (error: any) => void | Promise<void>;
|
|
6
7
|
};
|
|
7
8
|
export type QueueConstructorOptions = {
|
|
8
9
|
client: AWS.SQS;
|
|
@@ -17,7 +18,7 @@ export declare class Queue extends EventEmitter {
|
|
|
17
18
|
forever: boolean;
|
|
18
19
|
options: Omit<QueueOptions, "client" | "receiveOptions">;
|
|
19
20
|
constructor({ receiveOptions, client, ...otherOptions }: QueueConstructorOptions);
|
|
20
|
-
start<TMessage extends object>(callback: QueueCallback<TMessage>,
|
|
21
|
+
start<TMessage extends object>(callback: QueueCallback<TMessage>, canThrow?: boolean): Promise<void>;
|
|
21
22
|
processMessage<TMessage extends object>(message: AWS.SQS.Message, callback?: QueueCallback<TMessage>): Promise<void>;
|
|
22
23
|
delete(ReceiptHandle: string): Promise<{
|
|
23
24
|
$response: AWS.Response<{}, AWS.AWSError>;
|
package/lib/index.js
CHANGED
|
@@ -31,9 +31,10 @@ class Queue extends events_1.default {
|
|
|
31
31
|
this.client = client;
|
|
32
32
|
this.options = Object.assign({
|
|
33
33
|
sleepTimeout: 5000,
|
|
34
|
+
errorCallback: (e) => console.error(e)
|
|
34
35
|
}, otherOptions);
|
|
35
36
|
}
|
|
36
|
-
async start(callback,
|
|
37
|
+
async start(callback, canThrow = false) {
|
|
37
38
|
while (this.forever) {
|
|
38
39
|
try {
|
|
39
40
|
const { Messages } = await this.client
|
|
@@ -48,7 +49,7 @@ class Queue extends events_1.default {
|
|
|
48
49
|
catch (error) {
|
|
49
50
|
if (canThrow)
|
|
50
51
|
throw error;
|
|
51
|
-
await errorCallback(error);
|
|
52
|
+
await this.options.errorCallback(error);
|
|
52
53
|
await sleep(this.options.sleepTimeout);
|
|
53
54
|
}
|
|
54
55
|
}
|