feat: observe changes in repository to automatically clear cache
All checks were successful
Cadoles/bouncer/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/pr-master This commit looks good
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/command/common"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/proxy"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/setup"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
@ -72,6 +73,22 @@ func RunCommand() *cli.Command {
|
||||
|
||||
addrs, srvErrs := srv.Start(ctx.Context)
|
||||
|
||||
if observableProxyRepository, ok := proxyRepository.(store.Observable); ok {
|
||||
logger.Info(ctx.Context, "observing proxy repository changes")
|
||||
observableProxyRepository.Changes(ctx.Context, func(c store.Change) {
|
||||
logger.Info(ctx.Context, "proxy change detected, clearing cache")
|
||||
srv.ClearProxyCache()
|
||||
})
|
||||
}
|
||||
|
||||
if observableLayerRepository, ok := layerRepository.(store.Observable); ok {
|
||||
logger.Info(ctx.Context, "observing layer repository changes")
|
||||
observableLayerRepository.Changes(ctx.Context, func(c store.Change) {
|
||||
logger.Info(ctx.Context, "layer change detected, clearing cache")
|
||||
srv.ClearLayerCache()
|
||||
})
|
||||
}
|
||||
|
||||
// Clear director's cache on SIGUSR2
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGUSR2)
|
||||
@ -80,8 +97,9 @@ func RunCommand() *cli.Command {
|
||||
for {
|
||||
select {
|
||||
case <-sig:
|
||||
logger.Info(ctx.Context, "received sigusr2, clearing cache")
|
||||
srv.ClearCache()
|
||||
logger.Info(ctx.Context, "received sigusr2, clearing whole cache")
|
||||
srv.ClearProxyCache()
|
||||
srv.ClearLayerCache()
|
||||
case <-ctx.Context.Done():
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user