as

Projects / redban

redban

A token bucket whose state is a file. It wraps a command so the next run remembers the last one.

Why

movie reads Reddit without an authenticated quota. One process that fires every request will spend that quota and then fail halfway through a genre. The limit has to survive the process. An in-memory bucket resets every time you rerun the tool.

Diagrams

A solid outline is the path in the repo. A dashed outline is the alternative that shape is refusing.

redban -- then the command. The token bucket is a file, so the next run remembers the last one. movie uses it. A one-off curl can use the same file.

flowchart TD
  cmd["redban -- command"]
  file["Token bucket file"]
  run["The wrapped command"]
  cmd --> file --> run
  class cmd,file,run chosen
          

An in-memory bucket resets every time the tool starts, which spends the unauthenticated Reddit quota halfway through a genre. The file does not know why a host returned 429. It only counts the tokens you configured.

flowchart TD
  q{The next run}
  q -->|"the file still has the count"| disk["Bucket on disk"]
  q -->|"the count starts over"| mem["In-memory bucket"]
  class disk chosen
  class mem rejected
          

Why this shape

The interface is a wrapper: redban -- curl .... The bucket lives on disk. Any command can sit behind it, so movie does not grow its own sleep loop and a one-off curl can use the same file. The wrapper is the policy. The command is whatever you were going to run.

Where it breaks

Two machines do not share the file. Two processes on one machine can race the read-modify-write if they hit the file together. And the bucket does not know why Reddit returned 429. It only knows how many tokens you told it you had.