Answer a repeated ntfy message with its earlier job
Once queued jobs survive a restart, a crash in the second between queueing an ntfy message and saving the subscription's state would print the message twice: the replay offers it again. A card is now submitted as unique by its message's ID. If the queue already holds that source and reference, Submit queues nothing and returns the earlier job, or its ID and source once its status is gone, and logs the repeat. The queue keeps the last 512 references of each source apart from the statuses, so queue.history = 0 cannot defeat the check, and they come back on restore. A replayed message that quiet hours or the paper budget would hold for a digest never reaches Submit, so the check could not answer it, and it would print again as a digest row. Before it holds a message, the subscription now asks the queue through its handler whether it holds that message's card; if so, the message counts as printed and is not held. Only unique jobs take part. On the HTTP routes the reference is a request ID, which a client may set, so a check on it could answer a new request with an old job. A unique insert is stored with a sync, since the subscription treats the message as dealt with once it is queued. 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
792ee26af5
commit
8b8b7da0c6
8 files changed
+336
-17
No files matched your search
@@ -163,6 +163,12 @@ type Handler interface {
|
||||
// Digest prints the messages held back on one receipt. An error is
|
||||
// retried as for Message, while the subscription goes on reading.
|
||||
Digest(ctx context.Context, d Digest) error
|
||||
|
||||
// Queued reports whether the print queue already holds the card of m:
|
||||
// one queued before a restart that lost the subscription's record of
|
||||
// it. Such a message is not held for a digest, where it would print
|
||||
// again.
|
||||
Queued(m Message) bool
|
||||
}
|
||||
|
||||
// Subscriber reads the messages of an ntfy server's topics as they are
|
||||
@@ -520,11 +526,15 @@ func (r *run) deliver(ctx context.Context, m Message, now time.Time) bool {
|
||||
r.log.Debug("ntfy message dropped in quiet hours", "ntfy_id", m.ID)
|
||||
return true
|
||||
}
|
||||
r.hold(m, updated, true, now)
|
||||
if !r.queued(m) {
|
||||
r.hold(m, updated, true, now)
|
||||
}
|
||||
return true
|
||||
}
|
||||
if priority < r.o.BypassPriority && (!r.budget.room(now) || (r.held.Count > 0 && !quiet)) {
|
||||
r.hold(m, updated, false, now)
|
||||
if !r.queued(m) {
|
||||
r.hold(m, updated, false, now)
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := r.h.Message(ctx, m, updated); err != nil {
|
||||
@@ -541,6 +551,19 @@ func (r *run) deliver(ctx context.Context, m Message, now time.Time) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// queued reports whether the print queue already holds m's card, queued
|
||||
// before a restart that lost the save of m. m then counts as printed and
|
||||
// is not held, since a digest row would print it again; a message that is
|
||||
// not held reaches the queue, whose own check answers it.
|
||||
func (r *run) queued(m Message) bool {
|
||||
if m.ID == "" || !r.h.Queued(m) {
|
||||
return false
|
||||
}
|
||||
r.printed.add(m.Sequence())
|
||||
r.log.Debug("ntfy message already queued", "ntfy_id", m.ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// hold keeps m for the next digest. Only a message that gets a row counts
|
||||
// as printed; one past the rows is only counted on the digest.
|
||||
func (r *run) hold(m Message, updated, overnight bool, now time.Time) {
|
||||
|
||||
Reference in new issue
Block a user