UNPKG

event-message-broker

Version:

A Message Bus that uses AWS Stack and RabbitMQ

50 lines (49 loc) 2.25 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { SchedulerClient, CreateScheduleCommand, TagResourceCommand } from "@aws-sdk/client-scheduler"; import { v4 } from "uuid"; import { TOPIC_ARN_TEMPLATE } from "../utils/constants"; import { Configuration } from "../../application/utils/configurations"; export class EventBridgeService extends SchedulerClient { schedule(params) { return __awaiter(this, void 0, void 0, function* () { const scheduleName = v4(); const command = new CreateScheduleCommand({ Name: scheduleName, Description: 'Schedule a message', Target: { Arn: TOPIC_ARN_TEMPLATE(params.TopicName), RoleArn: process.env.AWS_ROLE_ARN, Input: JSON.stringify(params.Message) }, FlexibleTimeWindow: { Mode: 'OFF' }, ScheduleExpression: `at(${params.ScheduleDate.toISOString()})`, ActionAfterCompletion: 'DELETE' }); const output = yield this.send(command); yield this.tag(output.ScheduleArn); return { Id: scheduleName, ScheduleArn: output.ScheduleArn }; }); } tag(resourceArn) { return __awaiter(this, void 0, void 0, function* () { const command = new TagResourceCommand({ ResourceArn: resourceArn, Tags: Configuration.tags }); yield this.send(command); }); } }