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:
1 parent
7e6cda16f8
commit
9b25c1bfd3
6 files changed
+89
-9
No files matched your search
@@ -25,11 +25,14 @@ func (f fakeRenderer) Render(_ context.Context, job receipt.Job) ([]byte, error)
|
||||
|
||||
// fakeSender fails the first failures sends as a failed dial does, before
|
||||
// beforeWrite. Then it calls beforeWrite, fails the next writeFailures
|
||||
// sends as a failed write does, and records data.
|
||||
// sends as a failed write does, and records data. script, while it lasts,
|
||||
// says how each send ends instead: "dial" or "write" fails it there, and
|
||||
// anything else goes on as above.
|
||||
type fakeSender struct {
|
||||
mu sync.Mutex
|
||||
failures int
|
||||
writeFailures int
|
||||
script []string
|
||||
sent []string
|
||||
block chan struct{} // if set, Send waits for it to close
|
||||
}
|
||||
@@ -39,11 +42,20 @@ func (f *fakeSender) Send(_ context.Context, data []byte, beforeWrite func() err
|
||||
<-f.block
|
||||
}
|
||||
f.mu.Lock()
|
||||
if f.failures > 0 {
|
||||
f.failures--
|
||||
step := ""
|
||||
if len(f.script) > 0 {
|
||||
step, f.script = f.script[0], f.script[1:]
|
||||
}
|
||||
if step == "dial" || f.failures > 0 {
|
||||
if step != "dial" {
|
||||
f.failures--
|
||||
}
|
||||
f.mu.Unlock()
|
||||
return errors.New("printer offline")
|
||||
}
|
||||
if step == "write" {
|
||||
f.writeFailures++
|
||||
}
|
||||
f.mu.Unlock()
|
||||
if err := beforeWrite(); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user