Skip to content

Commit

Permalink
fix(slack): Limit log for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Jul 5, 2024
1 parent 1077b25 commit 09a9e93
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/bot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (c *CommandInstance) Execute(ctx domain.Context) error {
cmd.Stdout = &buf
cmd.Stderr = &buf

const logLimit = 9900
logLimit := ctx.MessageLimit() - 100 /* margin */

err := cmd.Run()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/bot/slack/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (ctx *slackContext) L() *zap.Logger {
)
}

func (ctx *slackContext) MessageLimit() int {
// https://stackoverflow.com/questions/60344831/slack-api-invalid-block
return 2500
}

func (ctx *slackContext) sendSlackMessage(channelID string, text string) error {
api := ctx.api
return utils.WithRetry(ctx, 10, func(ctx context.Context) error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/bot/traq/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (ctx *traqContext) L() *zap.Logger {
)
}

func (ctx *traqContext) MessageLimit() int {
return 9900
}

// sendTRAQMessage traQにメッセージ送信
func (ctx *traqContext) sendTRAQMessage(channelID string, text string) error {
api := ctx.api
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Context interface {

// L returns logger.
L() *zap.Logger
MessageLimit() int

// ReplyBad コマンドメッセージにBadスタンプをつけて返信します
ReplyBad(message ...string) error
Expand Down

0 comments on commit 09a9e93

Please sign in to comment.