event-message-broker
Version:
A Message Bus that uses AWS Stack and RabbitMQ
54 lines (53 loc) • 2.48 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventBridgeService = void 0;
const client_scheduler_1 = require("@aws-sdk/client-scheduler");
const uuid_1 = require("uuid");
const constants_1 = require("../utils/constants");
const configurations_1 = require("../../application/utils/configurations");
class EventBridgeService extends client_scheduler_1.SchedulerClient {
schedule(params) {
return __awaiter(this, void 0, void 0, function* () {
const scheduleName = (0, uuid_1.v4)();
const command = new client_scheduler_1.CreateScheduleCommand({
Name: scheduleName,
Description: 'Schedule a message',
Target: {
Arn: (0, constants_1.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 client_scheduler_1.TagResourceCommand({
ResourceArn: resourceArn,
Tags: configurations_1.Configuration.tags
});
yield this.send(command);
});
}
}
exports.EventBridgeService = EventBridgeService;