Skip to content

Commit

Permalink
adding in config to trigger redis mode on service start
Browse files Browse the repository at this point in the history
  • Loading branch information
maplebed committed Jun 6, 2019
1 parent 98774b4 commit 9c583f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 12 additions & 2 deletions cmd/samproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var version string

type Options struct {
ConfiFile string `short:"c" long:"config" description:"Path to config file" default:"/etc/samproxy/samproxy.toml"`
PeerType string `short:"p" long:"peer_type" description:"Peer type - should be redis or file" default:"file"`
Version bool `short:"v" long:"version" description:"Print version number and exit"`
}

Expand All @@ -54,8 +55,17 @@ func main() {
os.Exit(0)
}

c := &config.FileConfig{Path: opts.ConfiFile}
err := c.Start()
var c config.Config
var err error
// either the flag or the env var will kick us in to redis mode
if opts.PeerType == "redis" || os.Getenv(config.RedisHostEnvVarName) != "" {
c = &config.RedisPeerFileConfig{}
c.(*config.RedisPeerFileConfig).Path = opts.ConfiFile
err = c.(*config.RedisPeerFileConfig).Start()
} else {
c = &config.FileConfig{Path: opts.ConfiFile}
err = c.(*config.FileConfig).Start()
}
if err != nil {
fmt.Printf("unable to load config: %+v\n", err)
os.Exit(1)
Expand Down
7 changes: 0 additions & 7 deletions config/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,15 @@ func (rc *RedisPeerFileConfig) watchPeers() {
sort.Strings(oldPeerList)
tk := time.NewTicker(refreshCacheInterval)

defer func() {
fmt.Printf("leaving watchPeers\n")
}()

for range tk.C {
fmt.Printf("watchPeers: starting tick\n")
currentPeers, err := rc.peerStore.GetMembers(context.TODO())
if err != nil {
fmt.Printf("watchPeers: got error %+v|n", err)
// TODO maybe do something better here?
continue
}
sort.Strings(currentPeers)
if !equal(oldPeerList, currentPeers) {
// update peer list and trigger callbacks saying the peer list has changed
fmt.Printf("peer list has changed; new peer list +%v\n", currentPeers)
rc.peerLock.Lock()
rc.peers = currentPeers
oldPeerList = currentPeers
Expand Down

0 comments on commit 9c583f5

Please sign in to comment.