blob: cf4f4c5183b3294517b9c870cf97b1ba46761a79 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { TracingLogger } from "@/shared/log";
import { WidgetRequestT } from "@/shared/schema";
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
import { ProcessorResponse, WidgetRequestProcessor } from ".";
export class SQSWidgetRequestProcessor implements WidgetRequestProcessor {
private sqsClient: SQSClient;
private queueUrl: string;
private logger: TracingLogger;
constructor(sqsClient: SQSClient, queueUrl: string, logger: TracingLogger) {
this.sqsClient = sqsClient;
this.queueUrl = queueUrl;
this.logger = logger;
}
public async handle(
widgetRequest: WidgetRequestT,
): Promise<ProcessorResponse> {
const MessageBody = JSON.stringify(widgetRequest);
this.logger.info(`Handling WidgetRequest=(${MessageBody})`);
const sendMessage = new SendMessageCommand({
QueueUrl: this.queueUrl,
MessageBody,
});
await this.sqsClient.send(sendMessage);
return { success: true, message: "added to queue" };
}
}
|