Compare commits

...

No commits in common. "a0876409c5938f2dfae8d740c52d40eee099d4ca" and "84f68648e19292299fd77a9064e08006692ff129" have entirely different histories.

4 changed files with 12 additions and 13 deletions

View File

@ -2,9 +2,17 @@ linters:
fast: true
presets:
- bugs
- comment
- complexity
- error
- format
- import
- metalinter
- module
- performance
- sql
- style
- test
- unused
disable:
- wsl

View File

@ -70,7 +70,7 @@ func main() {
log.Panicf("redis ping: %v", err)
}
perDomainLimiter := redisleaky.New(
perDomainLimiter, err := redisleaky.New(
rate.Every(time.Duration(float64(time.Second)*cfg.PerDomainRateLimitEvery)),
int64(cfg.PerDomainRateLimitCapacity),
redisClient,

View File

@ -2,7 +2,6 @@ package pwextractor
import (
"context"
"errors"
"fmt"
"github.com/egor3f/rssalchemy/internal/limiter"
"github.com/egor3f/rssalchemy/internal/models"
@ -95,8 +94,6 @@ func (e *PwExtractor) Stop() error {
return nil
}
const MAX_RETRIES = 3 // todo: config
func (e *PwExtractor) visitPage(task models.Task, cb func(page playwright.Page) error) (errRet error) {
baseDomain, scheme, err := parseBaseDomain(task.URL)
@ -217,13 +214,7 @@ func (e *PwExtractor) visitPage(task models.Task, cb func(page playwright.Page)
}
}
for retry := 0; retry < MAX_RETRIES; retry++ {
_, err = page.Goto(task.URL, playwright.PageGotoOptions{Timeout: pwDuration("10s")})
if !errors.Is(err, playwright.ErrTimeout) {
break
}
}
if err != nil {
if _, err := page.Goto(task.URL, playwright.PageGotoOptions{Timeout: pwDuration("10s")}); err != nil {
return fmt.Errorf("goto page: %w", err)
}
log.Debugf("Url %s visited, starting cb", task.URL)

View File

@ -28,7 +28,7 @@ func New(
capacity int64,
redisClient *redis.Client,
prefix string,
) *Limiter {
) (*Limiter, error) {
l := Limiter{
rate: time.Duration(float64(time.Second) / float64(rateLimit)),
capacity: capacity,
@ -36,7 +36,7 @@ func New(
redisPool: rsgoredis.NewPool(redisClient),
prefix: prefix,
}
return &l
return &l, nil
}
func (l *Limiter) Limit(ctx context.Context, key string) (time.Duration, error) {