Skip to content

Commit

Permalink
Add timeout option (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
  • Loading branch information
saswatamcode committed Aug 3, 2021
1 parent 946757e commit 2dc3552
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/mdformatter/linktransformer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"regexp"
"strconv"
"time"

"github.com/pkg/errors"
"gopkg.in/yaml.v3"
Expand All @@ -20,6 +21,9 @@ type Config struct {
Version int

Validators []ValidatorConfig `yaml:"validators"`
Timeout string `yaml:"timeout"`

timeout time.Duration
}

type ValidatorConfig struct {
Expand Down Expand Up @@ -72,6 +76,14 @@ func ParseConfig(c []byte) (Config, error) {
return Config{}, errors.Wrapf(err, "parsing YAML content %q", string(c))
}

if cfg.Timeout != "" {
var err error
cfg.timeout, err = time.ParseDuration(cfg.Timeout)
if err != nil {
return Config{}, errors.Wrap(err, "parsing timeout duration")
}
}

if len(cfg.Validators) <= 0 {
return Config{}, errors.New("No validator provided")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/mdformatter/linktransformer/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func NewValidator(ctx context.Context, logger log.Logger, linksValidateConfig []
// Set very soft limits.
// E.g github has 50-5000 https://docs.github.com/en/free-pro-team@latest/rest/reference/rate-limit limit depending
// on api (only search is below 100).
if config.Timeout != "" {
v.c.SetRequestTimeout(config.timeout)
}
if err := v.c.Limit(&colly.LimitRule{
DomainGlob: "*",
Parallelism: 100,
Expand Down

0 comments on commit 2dc3552

Please sign in to comment.