mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
slacknotifier: apply rate limiter to 1 message per second
This commit is contained in:
parent
cd340bd596
commit
7e9b768e4c
|
@ -3,13 +3,18 @@ package slacknotifier
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/slack-go/slack"
|
||||
)
|
||||
|
||||
var limiter = rate.NewLimiter(rate.Every(1*time.Second), 1)
|
||||
|
||||
type notifyTask struct {
|
||||
Channel string
|
||||
Opts []slack.MsgOption
|
||||
|
@ -55,6 +60,7 @@ func (n *Notifier) worker() {
|
|||
return
|
||||
|
||||
case task := <-n.taskC:
|
||||
limiter.Wait(ctx)
|
||||
_, _, err := n.client.PostMessageContext(ctx, task.Channel, task.Opts...)
|
||||
if err != nil {
|
||||
log.WithError(err).
|
||||
|
|
Loading…
Reference in New Issue
Block a user