Move the archive files into their own package (closes #541)
check / check (push) Waiting to run

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
rename lock, 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 rename lock from archive.Archives.RenameLock, and
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 was merged in pull request #552.
This commit is contained in:
2026-10-15 21:03:43 +02:00
parent f10440b7cc
commit 0cdda43e6c
42 changed files with 2178 additions and 1772 deletions
+7 -7
View File
@@ -16,8 +16,8 @@ import (
"github.com/stretchr/testify/require"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"sneak.berlin/go/webhooker/internal/archive"
"sneak.berlin/go/webhooker/internal/database"
"sneak.berlin/go/webhooker/internal/delivery"
"sneak.berlin/go/webhooker/internal/handlers"
"sneak.berlin/go/webhooker/internal/session"
)
@@ -180,7 +180,7 @@ func failSaveOnTable(
}
// archivePathFor returns the archive database path the
// delivery engine would use for a database target: beside the
// archive writers would use for a database target: beside the
// webhook's event database in the data directory.
func archivePathFor(
t *testing.T,
@@ -192,7 +192,7 @@ func archivePathFor(
return filepath.Join(
filepath.Dir(mgr.DBPath(wh.ID)),
delivery.ArchiveFileName(wh.Name, tgt.Name, tgt.ID),
archive.FileName(wh.Name, tgt.Name, tgt.ID),
)
}
@@ -228,9 +228,9 @@ func postRequest(
}
// TestHandleSourceDelete_EvictsArchiveWriter proves that
// deleting a webhook reaches the delivery engine and releases
// the webhook's archive writers, exercised through the real
// deletion handler rather than by calling the engine directly.
// deleting a webhook releases the webhook's archive writers,
// exercised through the real deletion handler rather than by
// calling the archive writers directly.
func TestHandleSourceDelete_EvictsArchiveWriter(t *testing.T) {
t.Parallel()
@@ -290,7 +290,7 @@ func TestHandleSourceDelete_KeepsArchiveFile(t *testing.T) {
wh := seedWebhook(t, db)
tgt := seedTarget(t, db, wh.ID, database.TargetTypeDatabase)
// Place an archive file where the delivery engine would.
// Place an archive file where the archive writers would.
archivePath := archivePathFor(t, mgr, wh, tgt)
require.NoError(
t,