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

+6
View File
@@ -150,6 +150,11 @@ type Meta struct {
// Ref identifies the job at its source, e.g. the ID of the request
// that sent it, or of the ntfy message.
Ref string
// Sequence is the ntfy notification a card came from,
// "<topic>/<sequence>"; empty for other jobs. It is stored with the
// job.
Sequence string
}
// entry is a job the queue keeps.
@@ -265,6 +270,7 @@ func (q *Queue) Submit(job receipt.Job, meta Meta) (Status, error) {
ID: id,
Source: meta.Source,
Ref: meta.Ref,
Sequence: meta.Sequence,
CreatedAt: time.Now().UTC(),
Deliveries: []Delivery{
{Seq: q.nextDelivery, Printer: DefaultPrinter, State: StoredQueued},
@@ -595,3 +595,25 @@ func waitFor(t *testing.T, cond func() bool) {
time.Sleep(2 * time.Millisecond)
}
}
// A job's source, reference and ntfy notification are stored with it.
func TestMetaIsStored(t *testing.T) {
inner := printqueue.NewMemoryStore()
q := newQueueOn(inner, fakeRenderer{}, &fakeSender{}, discardLogger(), printqueue.Options{})
meta := printqueue.Meta{Source: "ntfy:home", Ref: "msg1", Sequence: "alerts/backup"}
st, err := q.Submit(job("x"), meta)
if err != nil {
t.Fatal(err)
}
loaded, err := inner.Load(context.Background())
if err != nil {
t.Fatal(err)
}
if len(loaded.Records) != 1 {
t.Fatalf("records %+v", loaded.Records)
}
r := loaded.Records[0]
if r.ID != st.ID || r.Source != meta.Source || r.Ref != meta.Ref || r.Sequence != meta.Sequence || r.Unique {
t.Errorf("record %+v, want the job's meta", r)
}
}