Add scheduler, rate limiting and headless mode.

Hard-coded 60s URL and 10s host floors with jitter and per-host
backoff, shared between dibs processes through a locked state file.
The scheduler shuffles due URLs each round and runs one worker per
host; 'dibs --headless' watches and logs JSON.
This commit is contained in:
Overlord committed 2026-10-14 09:04:15 +02:00
1 parent bb010356a0
commit 2175c0e5aa
30 files changed
+1434 -126

No files matched your search

+8 -11
View File
@@ -19,14 +19,14 @@ import (
lua "github.com/yuin/gopher-lua"
)
// Who sells the item, as parse reports it.
// The sellers parse reports.
const (
// SellerFirstParty: the shop itself sells it.
// SellerFirstParty means the shop itself sells the item.
SellerFirstParty = "first_party"
// SellerFulfilled: a marketplace seller sells it, but the shop ships it
// (e.g. Fulfilled by Amazon).
// SellerFulfilled means a marketplace seller sells the item and the shop
// ships it, as with Fulfilled by Amazon.
SellerFulfilled = "fulfilled"
// SellerThirdParty: a marketplace seller sells and ships it.
// SellerThirdParty means a marketplace seller sells and ships the item.
SellerThirdParty = "third_party"
SellerUnknown = "unknown"
)
@@ -172,7 +172,6 @@ func (p *Plugin) readTable(tbl *lua.LTable) error {
return nil
}
// Has reports whether the plugin defines hook.
func (p *Plugin) Has(hook string) bool {
p.mu.Lock()
defer p.mu.Unlock()
@@ -207,7 +206,7 @@ func (p *Plugin) call(ctx context.Context, hook string, nret int, args func(L *l
return nil
})
// A killed call can stop anywhere, so start over with a clean state.
// A killed call can stop anywhere, so the state is rebuilt from scratch.
if errors.Is(err, ErrTimeout) || errors.Is(err, ErrMemoryLimit) {
if rerr := p.reset(); rerr != nil { p.logger.Error("reloading plugin failed", "plugin", p.Name, "err", rerr) }
}
@@ -245,10 +244,9 @@ func (p *Plugin) Normalize(ctx context.Context, url string) (string, error) {
}
}
// Parse runs parse(doc, url) on a page.
func (p *Plugin) Parse(ctx context.Context, page []byte, url string) (*Result, error) {
// Parse the HTML before the call, so it does not count against the
// call's time and memory.
// The HTML is parsed before the call, so parsing does not count against
// the call's time and memory.
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(page))
if err != nil { return nil, fmt.Errorf("parsing HTML: %w", err) }
@@ -284,7 +282,6 @@ func (p *Plugin) CartLink(ctx context.Context, url, id string) (string, error) {
}
}
// Close frees the Lua state.
func (p *Plugin) Close() {
p.mu.Lock()
defer p.mu.Unlock()