Call a hook between dialling the printer and writing to it

The job store must commit a delivery's sending mark after the printer's
connection opens and before the first byte goes out, so that a job
interrupted mid-send is never sent again after a restart, while a dial
failure writes nothing. Send now takes a beforeWrite function for that
step. An error from it closes the connection with nothing written.

The write deadline is computed after beforeWrite returns, so a slow
synced commit does not use up printer.write_timeout. The queue passes
nil for now, so nothing changes in what is sent.

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 12:29:52 -06:00
1 parent 66531e7314
commit 50db21190b
4 files changed
+96 -9

No files matched your search

+5 -3
View File
@@ -86,9 +86,11 @@ type Renderer interface {
Render(ctx context.Context, job receipt.Job) ([]byte, error)
}
// Sender delivers bytes to the printer.
// Sender delivers bytes to the printer. It calls beforeWrite, if not nil,
// once it can write and before the first byte, and writes nothing when
// beforeWrite fails.
type Sender interface {
Send(ctx context.Context, data []byte) error
Send(ctx context.Context, data []byte, beforeWrite func() error) error
}
// Options configures a Queue.
@@ -259,7 +261,7 @@ func (q *Queue) print(runCtx, jobCtx context.Context, job receipt.Job, logger *s
}
delay := q.options.RetryDelay
for attempt := 1; ; attempt++ {
err := q.sender.Send(jobCtx, data)
err := q.sender.Send(jobCtx, data, nil)
if err == nil {
return attempt, nil
}