Fail deliveries on archive errors; validate expiry at creation (#43)
Some checks failed
check / check (push) Failing after 57s
Some checks failed
check / check (push) Failing after 57s
Two review findings on the database archiving target: - An archive error now records the attempt as failed with the error string and marks the delivery failed, instead of logging the error and reporting success. A target that could not do its one job must not claim it did. - The archive expiry is now actually configurable: the add-target form gains an expiry field for database targets, and the value is validated at creation time via the new delivery.ValidateArchiveExpiry (empty, "never", or a positive Go duration), rejecting bad values with a 400 at the only place a human can fix them, mirroring how Slack target URLs are validated at creation. Test updates: a forced archive failure asserts a failed delivery with a recorded error and no archive file; config builder tests cover empty/never/duration and rejection paths; the two engine tests that exercise the database target now build engines with a real webhook DB manager since archiving is no longer a no-op; the reopen-debounce test uses a wider window so parallel test load cannot make two rapid writes straddle it.
This commit is contained in:
@@ -16,8 +16,9 @@ import (
|
||||
// already persisted in the per-webhook event DB by the time
|
||||
// delivery runs; the database target additionally writes a
|
||||
// durable long-term copy into archive-{webhookID}.db and then
|
||||
// records a single successful attempt. See archiveWriter for
|
||||
// the close/reopen, auto-recreate, and expiry semantics.
|
||||
// records a single attempt whose outcome reflects whether the
|
||||
// archive write succeeded. See archiveWriter for the
|
||||
// close/reopen, auto-recreate, and expiry semantics.
|
||||
type databaseTarget struct {
|
||||
eng *Engine
|
||||
|
||||
@@ -27,10 +28,12 @@ type databaseTarget struct {
|
||||
|
||||
// Deliver implements Target. It archives the event, then
|
||||
// records one successful attempt and marks the delivery
|
||||
// delivered. Archiving errors are logged but do not fail the
|
||||
// delivery: the event is already durably stored in the
|
||||
// per-webhook event database, so the target stays
|
||||
// fire-and-forget.
|
||||
// delivered. An archiving error fails the delivery: the
|
||||
// attempt is recorded as failed with the error and the
|
||||
// delivery is marked failed, so a target that could not do
|
||||
// its one job (archiving) never reports success. The target
|
||||
// does not retry; the event remains durably stored in the
|
||||
// per-webhook event database.
|
||||
func (t *databaseTarget) Deliver(
|
||||
_ context.Context,
|
||||
webhookDB *gorm.DB,
|
||||
@@ -46,6 +49,17 @@ func (t *databaseTarget) Deliver(
|
||||
"event_id", d.EventID,
|
||||
"error", err,
|
||||
)
|
||||
|
||||
t.eng.recordResult(
|
||||
webhookDB, d, 1, false, 0, "",
|
||||
err.Error(), 0,
|
||||
)
|
||||
|
||||
t.eng.updateDeliveryStatus(
|
||||
webhookDB, d, database.DeliveryStatusFailed,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
t.eng.recordResult(
|
||||
|
||||
Reference in New Issue
Block a user