Move the archive files into their own package (closes #541)
check / check (push) Canceled after 0s

The SQLite archive files the database target writes are now managed by
internal/archive: file names, rotation, the writer of each target,
pruning, renames, the gzipped JSON export, the idle sweep, and the
lock renames run under, which was Handlers.renameMu. The database
target stays in internal/delivery and writes through archive.Writers;
the engine still closes the writers when it stops, so the stop order
is unchanged. The handlers take the lock, rename and evict through
archive.Archives.

Exported names drop their Archive prefix in the new package. The
tests moved with the code; the two that check a delivery's recorded
attempt stay in delivery.

Model: opus-5-5
This commit is contained in:
2026-10-15 18:09:57 +00:00
parent 40e8ecaab4
commit febf3c94c6
42 changed files with 2116 additions and 1770 deletions
+16 -5
View File
@@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/fx"
"go.uber.org/fx/fxtest"
"sneak.berlin/go/webhooker/internal/archive"
"sneak.berlin/go/webhooker/internal/config"
"sneak.berlin/go/webhooker/internal/database"
"sneak.berlin/go/webhooker/internal/delivery"
@@ -55,12 +56,14 @@ func (n *recordingNotifier) Tasks() []delivery.Task {
return out
}
// recordingArchives is a delivery.Archives that records what it
// recordingArchives is an archive.Archives that records what it
// was asked to do, so a test can prove that a deletion or rename
// path reached the delivery engine. After FailRenames, every
// path reached the archive writers. After FailRenames, every
// rename of that target fails with the given error. After
// BlockNextRename, the next rename is recorded and then waits.
// Lock and Unlock are a plain mutex, as in archive.Writers.
type recordingArchives struct {
renameMu sync.Mutex
mu sync.Mutex
evicted []string
evictedTargets []string
@@ -73,10 +76,10 @@ type recordingArchives struct {
// errInjectedRename is the failure a test hands FailRenames.
var errInjectedRename = errors.New("injected rename failure")
// errNameTaken is what the delivery engine returns when a file
// errNameTaken is what the archive writers return when a file
// already has an archive's new name, here archive-taken.db.
var errNameTaken = fmt.Errorf(
"%w: archive-taken.db", delivery.ErrArchiveNameTaken,
"%w: archive-taken.db", archive.ErrNameTaken,
)
// archiveRename is one recorded Rename call.
@@ -86,6 +89,14 @@ type archiveRename struct {
TargetName string
}
func (r *recordingArchives) Lock() {
r.renameMu.Lock()
}
func (r *recordingArchives) Unlock() {
r.renameMu.Unlock()
}
func (r *recordingArchives) EvictWebhook(webhookID string) {
r.mu.Lock()
defer r.mu.Unlock()
@@ -265,7 +276,7 @@ func newTestAppWithConfig(
func() *recordingArchives {
return &recordingArchives{}
},
func(r *recordingArchives) delivery.Archives {
func(r *recordingArchives) archive.Archives {
return r
},
func() *testCircuitBreakers {