Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout option to links.validate.config #69

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start with that, if needed we could do also per validator with this being default.


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