Skip to content

Commit

Permalink
fix(tgc): add rate limit to avoid frequent flood wait in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Aug 23, 2023
1 parent 12fdbb8 commit 83d879a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/internal/tgc/tgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (

"github.com/cenkalti/backoff/v4"
"github.com/gotd/contrib/middleware/floodwait"
"github.com/gotd/contrib/middleware/ratelimit"
tdclock "github.com/gotd/td/clock"
"github.com/gotd/td/telegram"
"github.com/gotd/td/telegram/dcs"
"github.com/spf13/viper"
"go.uber.org/zap"
"golang.org/x/time/rate"

"github.com/iyear/tdl/pkg/clock"
"github.com/iyear/tdl/pkg/consts"
Expand Down Expand Up @@ -87,6 +89,8 @@ func New(ctx context.Context, login bool, middlewares ...telegram.Middleware) (*
appId, appHash = telegram.TestAppID, telegram.TestAppHash
opts.DC = 2
opts.DCList = dcs.Test()
// add rate limit to avoid frequent flood wait
opts.Middlewares = append(opts.Middlewares, ratelimit.New(rate.Every(100*time.Millisecond), 5))
}

logger.From(ctx).Info("New telegram client",
Expand Down

0 comments on commit 83d879a

Please sign in to comment.