Add feature to clean up data in Consul

Running the app with `-app.pipe.cleanup-only` will delete any records
from Consul that are marked as deleted more than ten minutes ago, then
exit.

This is so you can set it to run as a cronjob, e.g. once an hour.
This commit is contained in:
Bryan Boreham
2020-01-08 18:18:06 +00:00
parent 8b1296c892
commit a1dbcf05ad
8 changed files with 65 additions and 7 deletions

View File

@@ -267,6 +267,12 @@ func appMain(flags appFlags) {
log.Fatalf("Error creating pipe router: %v", err)
return
}
if flags.cleanupPipesOnly {
pipeRouter.CleanUp()
return
}
pipeRouter.Start()
// Start background version checking
checkpoint.CheckInterval(&checkpoint.CheckParams{

View File

@@ -168,6 +168,7 @@ type appFlags struct {
controlRouterURL string
controlRPCTimeout time.Duration
pipeRouterURL string
cleanupPipesOnly bool
natsHostname string
memcachedHostname string
memcachedTimeout time.Duration
@@ -381,6 +382,7 @@ func setupFlags(flags *flags) {
flag.StringVar(&flags.app.controlRouterURL, "app.control.router", "local", "Control router to use (local or sqs)")
flag.DurationVar(&flags.app.controlRPCTimeout, "app.control.rpctimeout", time.Minute, "Timeout for control RPC")
flag.StringVar(&flags.app.pipeRouterURL, "app.pipe.router", "local", "Pipe router to use (local)")
flag.BoolVar(&flags.app.cleanupPipesOnly, "app.pipe.cleanup-only", false, "Clean up deleted pipes and exit")
flag.StringVar(&flags.app.natsHostname, "app.nats", "", "Hostname for NATS service to use for shortcut reports. If empty, shortcut reporting will be disabled.")
flag.StringVar(&flags.app.memcachedHostname, "app.memcached.hostname", "", "Hostname for memcached service to use when caching reports. If empty, no memcached will be used.")
flag.DurationVar(&flags.app.memcachedTimeout, "app.memcached.timeout", 100*time.Millisecond, "Maximum time to wait before giving up on memcached requests.")