diff options
Diffstat (limited to 'event.go')
| -rw-r--r-- | event.go | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -23,8 +23,46 @@ func (h *HyperT) RestartDaemon() { me.killcount += 1 } +// checks if the cluster is ready and stable +func clusterReady() bool { + last := time.Since(me.unstable) + if last > 133*time.Second { + // the cluster has not been stable for 133 seconds + log.Warn("clusterReady() is stable for 133s") + return true + } + log.Warn("clusterReady() is unstable for", shell.FormatDuration(last)) + return false +} + +func (d *DropletT) dropletReady() bool { + if d.CurrentState == "ON" { + log.Warn("EVENT start droplet is already ON") + return false + } + if d.starts > 2 { + log.Warn("EVENT start droplet has already been started", d.starts, "times") + return false + } + return true +} + func (h *HyperT) Start(d *DropletT) { - url := "http://" + h.Hostname + ":2520/start?" + d.Hostname + if ! clusterReady() { + return + } + if ! d.dropletReady() { + return + } + + url := "http://" + h.Hostname + ":2520/start?start=" + d.Hostname s := shell.Wget(url) - log.Info("EVENT start droplet", url, s) + log.Warn("EVENT start droplet url:", url) + log.Warn("EVENT start droplet response:", s) + + // increment the counter for a start attempt working + d.starts += 1 + + // mark the cluster as unstable so droplet starts can be throttled + me.unstable = time.Now() } |
