Skip to content

Commit

Permalink
Print warn logs when it fails to send notification (#40)
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
  • Loading branch information
musaprg authored Dec 5, 2023
1 parent df474c9 commit 9eccfb5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/rarejobctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,26 @@ End: %s
func postMessage(text string) {
switch {
case slackAPIToken != "":
slackAPI.PostMessage(slackChannel, slack.MsgOptionText(text, false), slack.MsgOptionAsUser(true))
_, _, err := slackAPI.PostMessage(slackChannel, slack.MsgOptionText(text, false), slack.MsgOptionAsUser(true))
if err != nil {
zap.L().Warn("failed to post message to slack", zap.Error(err))
}

case slackWebhookURL != "":
slack.PostWebhook(slackWebhookURL, &slack.WebhookMessage{
err := slack.PostWebhook(slackWebhookURL, &slack.WebhookMessage{
Text: text,
})
if err != nil {
zap.L().Warn("failed to post message to slack", zap.Error(err))
}

case discordWebhookClient != nil:
discordWebhookClient.CreateContent(text)
_, err := discordWebhookClient.CreateContent(text)
if err != nil {
zap.L().Warn("failed to post message to discord", zap.Error(err))
}

default:
zap.L().Warn("no slack or discord webhook is configured")
}
}

0 comments on commit 9eccfb5

Please sign in to comment.