feat: add a crawl delay function in kage clone to honor the Crawl-del…#57
Merged
Conversation
Owner
|
Love this. It adds more respect for However, I found an awesome package that already implements the rate-limiting logic, and we could reuse it: https://pkg.go.dev/golang.org/x/time/rate import "golang.org/x/time/rate"Then add a field: type Cloner struct {
...
crawlLimiter *rate.Limiter
}And the setup is just: func (c *Cloner) setupCrawlDelayLimiter() {
if !c.cfg.RespectRobots || c.robots == nil || c.robots.CrawlDelay <= 0 {
c.crawlLimiter = nil
return
}
c.crawlLimiter = rate.NewLimiter(rate.Every(c.robots.CrawlDelay), 1)
}Then your function becomes: func (c *Cloner) waitForCrawlDelay(ctx context.Context) bool {
if c.crawlLimiter == nil {
return true
}
return c.crawlLimiter.Wait(ctx) == nil
}Underlying, it is almost same logic: https://cs.opensource.google/go/x/time/+/refs/tags/v0.15.0:rate/rate.go;l=253 |
…e parsed from robots.txt during clone.
2. add --craw-delay flag to specify/override robots directive.
20552bf to
4de9338
Compare
Contributor
Author
|
Thx for the suggestion! I've amended the commit to use rate pkg and added the --crawl-delay user flag. |
Owner
|
lgtm, I will cut new release soon! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a crawl delay function in kage clone to honor the Crawl-delay directive parsed from robots.txt.
The next step would be adding a user flag (--crawl-delay) under clone cmd to resolve #6 .