diff options
| author | Jason Cameron <git@jasoncameron.dev> | 2025-03-29 23:24:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-29 23:24:06 -0400 |
| commit | 0f41388bd78668ceae6d5c12b05868bd0ca8fd1f (patch) | |
| tree | e60f01da1b446e8ec98aa66a70da2969a7f4e9ad /cmd | |
| parent | 052316ba25c86d5dcc870cd5b4c045ea67110562 (diff) | |
| download | anubis-0f41388bd78668ceae6d5c12b05868bd0ca8fd1f.tar.xz anubis-0f41388bd78668ceae6d5c12b05868bd0ca8fd1f.zip | |
Add periodic cleanup job for DecayMap (#8) (#158)
* Add periodic cleanup job for DecayMap
see https://github.com/TecharoHQ/anubis/issues/8
* Refactor: Improve DecayMap cleanup tests and add Len method
- Refactored DecayMap cleanup tests to use the new Len method
for more precise assertions.
- Added a Len method to DecayMap to retrieve the number of
entries.
- Simplified conditional checks in Get method.
* chore(changelog): add entry
* fix(tests): Use Impl.expire for decaymap cleanup
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
---------
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/anubis/main.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go index a7e7350..4cee20c 100644 --- a/cmd/anubis/main.go +++ b/cmd/anubis/main.go @@ -135,6 +135,20 @@ func makeReverseProxy(target string) (http.Handler, error) { return rp, nil } +func startDecayMapCleanup(ctx context.Context, s *libanubis.Server) { + ticker := time.NewTicker(1 * time.Hour) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + s.CleanupDecayMap() + case <-ctx.Done(): + return + } + } +} + func main() { flagenv.Parse() flag.Parse() @@ -210,6 +224,8 @@ func main() { go metricsServer(ctx, wg.Done) } + go startDecayMapCleanup(ctx, s) + var h http.Handler h = s h = internal.RemoteXRealIP(*useRemoteAddress, *bindNetwork, h) |
