Store the ntfy notification a card came from

A card from an ntfy subscription now carries its notification,
"<topic>/<sequence ID>", in its Meta, and the queue stores it with the
job. ntfy's sequence IDs are per topic and one subscription reads
several topics, so the topic is part of the key; a message without a
sequence_id is its own sequence. Digests and jobs from the routes carry
none.

Nothing reads it yet: it lets an ntfy message_delete find the waiting
job of its notification, also after a restart, once cancelling comes.

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:47:03 -06:00
1 parent 8031135508
commit 792ee26af5
6 files changed
+73 -8

No files matched your search

+9 -7
View File
@@ -174,7 +174,7 @@ func (p *ntfyPrinter) Message(_ context.Context, m ntfy.Message, updated bool) e
env := p.env()
job, err := modules.Card(n, env.Card, env)
p.reportFallback(m.ID, err)
return p.submit(job, m.ID)
return p.submit(job, printqueue.Meta{Ref: m.ID, Sequence: m.Notification()})
}
// Digest prints the held messages on one receipt.
@@ -182,13 +182,15 @@ func (p *ntfyPrinter) Digest(_ context.Context, d ntfy.Digest) error {
env := p.env()
job, err := modules.DigestCard(d, env.Card, env)
p.reportFallback(digestRef, err)
return p.submit(job, digestRef)
return p.submit(job, printqueue.Meta{Ref: digestRef})
}
// submit validates job and queues it. Card and DigestCard return valid
// jobs, so a job that fails validation is a bug: it is logged and
// reported, and dropped rather than retried.
func (p *ntfyPrinter) submit(job receipt.Job, ref string) error {
// submit validates job and queues it with meta, from the subscription.
// Card and DigestCard return valid jobs, so a job that fails validation
// is a bug: it is logged and reported, and dropped rather than retried.
func (p *ntfyPrinter) submit(job receipt.Job, meta printqueue.Meta) error {
meta.Source = "ntfy:" + p.name
ref := meta.Ref
if err := job.Validate(); err != nil {
problems := 1
var ve *receipt.ValidationError
@@ -199,7 +201,7 @@ func (p *ntfyPrinter) submit(job receipt.Job, ref string) error {
reportNtfy(p.name, ref, fmt.Errorf("the receipt failed validation with %d problems", problems))
return nil
}
status, err := p.jobs.Submit(job, printqueue.Meta{Source: "ntfy:" + p.name, Ref: ref})
status, err := p.jobs.Submit(job, meta)
if err != nil {
return err
}
+7 -1
View File
@@ -244,13 +244,19 @@ func TestNtfyPrinter(t *testing.T) {
if len(q.jobs) != 2 {
t.Fatalf("%d jobs, want the card and the digest", len(q.jobs))
}
if q.metas[0] != (printqueue.Meta{Source: "ntfy:home", Ref: "msg1"}) || q.metas[1] != (printqueue.Meta{Source: "ntfy:home", Ref: "digest"}) {
if q.metas[0] != (printqueue.Meta{Source: "ntfy:home", Ref: "msg1", Sequence: "alerts/msg1"}) ||
q.metas[1] != (printqueue.Meta{Source: "ntfy:home", Ref: "digest"}) {
t.Errorf("metas %+v", q.metas)
}
if title := q.jobs[0].Elements[0].Title; title != "Disk almost full (updated)" {
t.Errorf("card title %q, want the update marked", title)
}
update := ntfy.Message{ID: "msg3", SequenceID: "disk", Event: "message", Topic: "alerts", Title: "Disk full"}
if err := p.Message(ctx, update, false); err != nil || len(q.metas) != 3 || q.metas[2].Sequence != "alerts/disk" {
t.Errorf("metas %+v, %v; want a card of a named sequence to carry its notification", q.metas, err)
}
q.err = printqueue.ErrQueueFull
if err := p.Message(ctx, m, false); !errors.Is(err, printqueue.ErrQueueFull) {
t.Errorf("err = %v, want the full queue back", err)