Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEAB-5860: Convert "ecs stopped task" event to Slack message #160

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion cloud-watch-to-slack-testing/deployment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,27 @@ function s3ActivityMessageText(message) {
return `${userName} generated S3 event ${eventName} from region ${awsRegion} for bucket ${bucketName} in Dockstore ${dockstoreEnvironment}`;
}

function ecsActivityMessageText(message) {
if (message["detail-type"] === "ECS Task State Change") {
return ecsTaskStateChangeMessageText(message);
} else {
return ecsAutoScalingMessageText(message);
}
}

function ecsTaskStateChangeMessageText(message) {
const taskArn = message?.detail?.taskArn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, for some reason I thought optional chaining was a TypeScript only feature. Good to know it's not. Looks like the feature was added to most browsers in 2020, so when I first started on Dockstore, it actually was TS-only, and I never noticed it was added to JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, for some reason I thought optional chaining was a TypeScript only feature. Good to know it's not. Looks like the feature was added to most browsers in 2020, so when I first started on Dockstore, it actually was TS-only, and I never noticed it was added to JS.

Looks like it got added to Node in version 14:
https://nodejs.medium.com/node-js-version-14-available-now-8170d384567e

const lastStatus = message?.detail?.lastStatus;
let messageText = `Task ${taskArn} is now ${lastStatus}`;
["startedAt", "stoppedAt", "stoppedReason"].forEach((name) => {
const value = message?.detail?.[name];
if (value != undefined) {
messageText += `\n${name}: ${value}`;
}
});
return messageText;
}

function ecsAutoScalingMessageText(message) {
const serviceName = message.detail.requestParameters.service;
const newDesiredCount = message.detail.requestParameters.desiredCount;
Expand All @@ -268,7 +289,7 @@ function messageTextFromMessageObject(message) {
} else if (message.source === "dockstore.deployer") {
return dockstoreDeployerMessageText(message);
} else if (message.source === "aws.ecs") {
return ecsAutoScalingMessageText(message);
return ecsActivityMessageText(message);
} else if (message.source === "aws.cloudwatch") {
return cloudWatchEventBridgeAlarmMessageText(message);
} else {
Expand Down
Loading