summaryrefslogtreecommitdiff
path: root/event.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-15 11:02:34 -0500
committerJeff Carr <[email protected]>2024-10-15 11:02:34 -0500
commit1c77ec7e63355cab48564a9fb49f34f55b5f0b15 (patch)
tree8d081863ea226465827f9d266b0e701da216220e /event.go
parentaa6b142b7c156b8f1925eb4af10b0b371263a129 (diff)
start from the command line works
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'event.go')
-rw-r--r--event.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/event.go b/event.go
index ee4bef0..2956b0e 100644
--- a/event.go
+++ b/event.go
@@ -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()
}