Show when a job was first sent to the printer

A failed job's error is its last attempt's, so it cannot say whether an
earlier attempt wrote part of the receipt: a first attempt cut off by a
write error and a second that fails to dial end with a dial error. Job
status now has sent_at, the time the first attempt was about to write
to the printer, taken from the delivery's first sending mark. A failed
job with sent_at reached the printer and may have printed in part; one
without it never did.

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:
57_WolveandClaude Opus 5.5 committed 2026-12-01 13:44:46 -06:00
1 parent 7e6cda16f8
commit 9b25c1bfd3
6 files changed
+89 -9

No files matched your search

@@ -222,6 +222,51 @@ func TestCommitsAndSyncs(t *testing.T) {
}
}
// sent_at is set by the first attempt that was about to write, and kept
// through later attempts; a failed dial sets nothing.
func TestSentAt(t *testing.T) {
for _, tt := range []struct {
name string
script []string
state printqueue.State
marks int
}{
{"printed", nil, printqueue.StateDone, 1},
{"after a failed dial", []string{"dial"}, printqueue.StateDone, 1},
{"never dialled", []string{"dial", "dial"}, printqueue.StateFailed, 0},
{"a write failed, then a dial", []string{"write", "dial"}, printqueue.StateFailed, 1},
{"a write failed, then printed", []string{"write"}, printqueue.StateDone, 2},
} {
t.Run(tt.name, func(t *testing.T) {
store := newTestStore(printqueue.NewMemoryStore())
sender := &fakeSender{script: tt.script}
q := newQueueOn(store, fakeRenderer{}, sender, discardLogger(), printqueue.Options{Retries: 1})
startQueue(t, q)
before := time.Now().UTC()
st, _ := q.Submit(job("x"), printqueue.Meta{})
got := waitForState(t, q, st.ID, tt.state)
var marks int
for _, c := range store.Commits() {
if c.op == "sending" {
marks++
}
}
if marks != tt.marks {
t.Errorf("%d sending marks, want %d", marks, tt.marks)
}
if tt.marks == 0 {
if got.SentAt != nil {
t.Errorf("sent_at %v, want none", got.SentAt)
}
return
}
if got.SentAt == nil || got.SentAt.Before(before) || got.SentAt.Before(*got.StartedAt) || got.SentAt.After(*got.FinishedAt) {
t.Errorf("status %+v, want sent_at between started_at and finished_at", got)
}
})
}
}
// The job the worker renders is the job submitted, read back from the
// store.
func TestJobRoundTripsThroughTheStore(t *testing.T) {