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 { 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" }; } }