Skip to content

Commit

Permalink
crop SNS message based on max size limit (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
damianxu88 authored Aug 16, 2023
1 parent 79efbce commit b344c48
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion service/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"mce.salesforce.com/sprinkler/orchard"
)

// https://docs.aws.amazon.com/sns/latest/api/API_Publish.html
const SNSMessageMaxBytes int = 262144

type ScheduleStatus int

const (
Expand Down Expand Up @@ -216,8 +219,9 @@ func notifyOwner(wf table.Workflow, orchardErr error) {
log.Println("[error] error initiating SNS client")
}

croppedErrMsg := truncate(errMsg, SNSMessageMaxBytes)
input := &sns.PublishInput{
Message: &errMsg,
Message: &croppedErrMsg,
TopicArn: wf.Owner,
}

Expand Down Expand Up @@ -266,3 +270,11 @@ func addInterval(someTime time.Time, every model.Every) time.Time {
}
panic(fmt.Sprintf("Every unit '%s' not recognized", every.Unit))
}

func truncate(str string, bytes int) string {
slice := []byte(str)
if len(slice) <= bytes {
return str
}
return string(slice[:bytes])
}

0 comments on commit b344c48

Please sign in to comment.