Keep finished jobs' content within queue.content_bytes
A job's content, its JSON, went from the store in the commit that finished it. The store is to keep it for longer, so that a finished job can be previewed or sent again by ID, but a count of jobs cannot bound that: at webserver.body_limit, 1000 finished jobs come to about 4 GB. The new key queue.content_bytes (default 64 MiB, 0 to 1 GiB) bounds the content of finished jobs instead, newest first. Statuses stay as queue.history says; a job past the budget keeps its status without its content. Unfinished jobs always keep their content, and so do uncertain ones while their status is kept, since a reprint needs it. What goes is dropped in the commit that finishes the job pushing it out. With the memory store the content is kept in memory, so the daemon may hold up to the budget more than before; at 1.5 KB per text job, the 1000 jobs of history take about 1.5 MB. Part of stage 1c of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4ef6d21258
commit
8031135508
9 files changed
+220
-32
No files matched your search
@@ -39,6 +39,9 @@ const MaxLineSpacing = 255
|
||||
// MaxCutFeed is the largest printer.cut_feed, the most ESC d feeds at once.
|
||||
const MaxCutFeed = 255
|
||||
|
||||
// MaxContentBytes is the largest queue.content_bytes, 1 GiB.
|
||||
const MaxContentBytes = 1 << 30
|
||||
|
||||
// Log formats accepted by [LogConfig.Format].
|
||||
const (
|
||||
LogFormatText = "text"
|
||||
@@ -313,6 +316,12 @@ type QueueConfig struct {
|
||||
|
||||
// History is the number of finished jobs whose status is kept.
|
||||
History int `mapstructure:"history"`
|
||||
|
||||
// ContentBytes is how many bytes of finished jobs' content are kept,
|
||||
// newest first. Unfinished jobs, and uncertain ones while their status
|
||||
// is kept, keep theirs whatever the total. It is an int64, as are the
|
||||
// sizes it bounds.
|
||||
ContentBytes int64 `mapstructure:"content_bytes"`
|
||||
}
|
||||
|
||||
// StateConfig configures where the daemon keeps what must survive a
|
||||
@@ -403,8 +412,9 @@ func Default() Config {
|
||||
},
|
||||
},
|
||||
Queue: QueueConfig{
|
||||
Size: 100,
|
||||
History: 1000,
|
||||
Size: 100,
|
||||
History: 1000,
|
||||
ContentBytes: 64 << 20,
|
||||
},
|
||||
Images: ImagesConfig{
|
||||
Timeout: 10 * time.Second,
|
||||
@@ -978,6 +988,8 @@ func (c *Config) Validate() error {
|
||||
|
||||
check(c.Queue.Size > 0, "queue.size must be positive")
|
||||
check(c.Queue.History >= 0, "queue.history must not be negative")
|
||||
check(c.Queue.ContentBytes >= 0 && c.Queue.ContentBytes <= MaxContentBytes,
|
||||
"queue.content_bytes must be 0-%d (1 GiB)", MaxContentBytes)
|
||||
|
||||
check(len(c.Ntfy.Subscriptions) == 0 || strings.TrimSpace(c.State.Dir) != "",
|
||||
`state.dir is required when an ntfy subscription is configured, e.g. "/var/lib/uberbringer"`)
|
||||
|
||||
@@ -406,7 +406,7 @@ func TestExampleConfigLoads(t *testing.T) {
|
||||
cfg.Printer.CutFeed != def.Printer.CutFeed ||
|
||||
cfg.Format.Timezone != def.Format.Timezone || cfg.Format.TimeLayout != def.Format.TimeLayout ||
|
||||
cfg.Ntfy.Format != def.Ntfy.Format || len(cfg.Ntfy.Markers) != 0 ||
|
||||
cfg.State != def.State || len(cfg.Ntfy.Subscriptions) != 0 {
|
||||
cfg.State != def.State || cfg.Queue != def.Queue || len(cfg.Ntfy.Subscriptions) != 0 {
|
||||
t.Error("example config values drifted from the defaults it documents")
|
||||
}
|
||||
}
|
||||
@@ -691,3 +691,32 @@ func TestValue(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// queue.content_bytes defaults to 64 MiB and takes 0 to 1 GiB.
|
||||
func TestLoadContentBytes(t *testing.T) {
|
||||
base := "[api]\nsecret = \"" + validSecret + "\"\n[printer]\naddress = \"p\"\n"
|
||||
cfg, err := config.Load(writeConfig(t, base))
|
||||
if err != nil || cfg.Queue.ContentBytes != 64<<20 {
|
||||
t.Fatalf("default content_bytes %d, %v; want 67108864", cfg.Queue.ContentBytes, err)
|
||||
}
|
||||
for _, tt := range []struct {
|
||||
value string
|
||||
want int64
|
||||
ok bool
|
||||
}{
|
||||
{"0", 0, true},
|
||||
{"1073741824", 1 << 30, true},
|
||||
{"-1", 0, false},
|
||||
{"1073741825", 0, false},
|
||||
} {
|
||||
cfg, err := config.Load(writeConfig(t, base+"[queue]\ncontent_bytes = "+tt.value+"\n"))
|
||||
switch {
|
||||
case tt.ok && err != nil:
|
||||
t.Errorf("content_bytes = %s: %v", tt.value, err)
|
||||
case tt.ok && cfg.Queue.ContentBytes != tt.want:
|
||||
t.Errorf("content_bytes = %s gave %d", tt.value, cfg.Queue.ContentBytes)
|
||||
case !tt.ok && (err == nil || !strings.Contains(err.Error(), "queue.content_bytes must be 0-1073741824")):
|
||||
t.Errorf("content_bytes = %s: err %v, want it refused", tt.value, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user