Rename saveState to state.save
This commit is contained in:
parent
d85fb84398
commit
28a31efc1f
|
@ -90,7 +90,7 @@ func (c *Cluster) Join(addrs []string) error {
|
||||||
|
|
||||||
// Leave saves the current state before leaving, then leaves the cluster
|
// Leave saves the current state before leaving, then leaves the cluster
|
||||||
func (c *Cluster) Leave() {
|
func (c *Cluster) Leave() {
|
||||||
c.saveState()
|
c.state.save()
|
||||||
c.ml.Leave(10 * time.Second)
|
c.ml.Leave(10 * time.Second)
|
||||||
c.ml.Shutdown() //nolint: errcheck
|
c.ml.Shutdown() //nolint: errcheck
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (c *Cluster) Members() <-chan []common.Node {
|
||||||
}
|
}
|
||||||
c.state.Nodes = nodes
|
c.state.Nodes = nodes
|
||||||
changes <- nodes
|
changes <- nodes
|
||||||
c.saveState()
|
c.state.save()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return changes
|
return changes
|
||||||
|
|
|
@ -18,12 +18,12 @@ type state struct {
|
||||||
|
|
||||||
const statePath = "/var/lib/wesher/state.json"
|
const statePath = "/var/lib/wesher/state.json"
|
||||||
|
|
||||||
func (c *Cluster) saveState() error {
|
func (s *state) save() error {
|
||||||
if err := os.MkdirAll(path.Dir(statePath), 0700); err != nil {
|
if err := os.MkdirAll(path.Dir(statePath), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stateOut, err := json.MarshalIndent(c.state, "", " ")
|
stateOut, err := json.MarshalIndent(s, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func Test_state_save_soad(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster.saveState()
|
cluster.state.save()
|
||||||
loaded := &state{}
|
loaded := &state{}
|
||||||
loadState(loaded)
|
loadState(loaded)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue