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

+10 -11
View File
@@ -10,14 +10,17 @@ import (
"time"
"github.com/pelletier/go-toml/v2"
"git.security-command.org/Overlord/dibs/internal/ratelimit"
)
// MinInterval is the shortest allowed polling interval per URL.
const MinInterval = 60 * time.Second
// MinInterval is the shortest allowed polling interval per URL. The
// scheduler enforces it too, whatever the config says.
const MinInterval = ratelimit.URLFloor
const (
// Seller policies for an item: sold by the shop itself; sold or at least
// shipped by it (e.g. Fulfilled by Amazon); or anyone.
// The seller policies accept offers sold by the shop itself, offers it
// sells or only ships (such as Fulfilled by Amazon), or any offer.
SellerFirstParty = "first_party"
SellerFulfilled = "fulfilled"
SellerAny = "any"
@@ -30,7 +33,6 @@ const (
FormatJSON = "json"
)
// Defaults for keys that may be omitted.
const (
DefaultInterval = 3 * time.Minute
DefaultCooldown = 30 * time.Minute
@@ -48,7 +50,7 @@ type Config struct {
Items []Item `toml:"item"`
Accounts map[string]Account `toml:"accounts"`
Notify Notify `toml:"notify"`
// Plugins maps a plugin name to its file. After Load the paths are absolute.
// Plugins maps plugin names to files. Load makes the paths absolute.
Plugins map[string]string `toml:"plugins"`
Sandbox Sandbox `toml:"sandbox"`
@@ -89,7 +91,6 @@ type Webhook struct {
Format string `toml:"format"`
}
// Sandbox holds the limits for Lua plugin calls.
type Sandbox struct {
// Timeout applies to matches, parse and cart_link.
Timeout Duration `toml:"timeout"`
@@ -152,7 +153,6 @@ func (it Item) AcceptsSeller(seller string) bool {
return rank <= policyRanks[it.Seller]
}
// Options control validation that depends on the environment.
type Options struct {
// Builtins are the names of the embedded plugins.
Builtins []string
@@ -167,8 +167,7 @@ func DefaultPath() (string, error) {
return filepath.Join(dir, "dibs", "dibs.toml"), nil
}
// Load reads, decodes and validates the config at path. All problems found
// are returned together as Errors.
// Load returns every problem it finds at once, as Errors.
func Load(path string, opts Options) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil { return nil, err }
@@ -206,7 +205,7 @@ func Load(path string, opts Options) (*Config, error) {
switch {
case err == nil:
case errors.As(err, &strict):
// The rest of the document was decoded, so keep validating it.
// The rest of the document was decoded, so validation goes on.
for _, e := range strict.Errors {
msg := "unknown key"
if k := e.Key(); len(k) > 0 && k[len(k)-1] == "quantity" {