Monitor Instances now returns a tuple so an error can be passed instead of exiting on error. Tuple is: Result of action, error if it exists.
This commit is contained in:
parent
8f524eeec5
commit
c83e5d268a
2 changed files with 9 additions and 9 deletions
|
@ -124,7 +124,7 @@ func main() {
|
||||||
fmt.Println(resp.String())
|
fmt.Println(resp.String())
|
||||||
|
|
||||||
if resp.ResponseCode == aurora.ResponseCode_OK {
|
if resp.ResponseCode == aurora.ResponseCode_OK {
|
||||||
if !monitor.Instances(job.JobKey(), job.GetInstanceCount(), 5, 50) {
|
if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 5, 50); !ok || err != nil {
|
||||||
_, err := r.KillJob(job.JobKey())
|
_, err := r.KillJob(job.JobKey())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -176,7 +176,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.ResponseCode == aurora.ResponseCode_OK {
|
if resp.ResponseCode == aurora.ResponseCode_OK {
|
||||||
if !monitor.Instances(job.JobKey(), 0, 5, 50) {
|
if ok, err := monitor.Instances(job.JobKey(), 0, 5, 50); !ok || err != nil {
|
||||||
fmt.Println("Unable to kill all instances of job")
|
fmt.Println("Unable to kill all instances of job")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.ResponseCode == aurora.ResponseCode_OK {
|
if resp.ResponseCode == aurora.ResponseCode_OK {
|
||||||
if !monitor.Instances(job.JobKey(), job.GetInstanceCount()+numOfInstances, 5, 50) {
|
if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount()+numOfInstances, 5, 50); !ok || err != nil {
|
||||||
fmt.Println("Flexing up failed")
|
fmt.Println("Flexing up failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
monitors.go
12
monitors.go
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/rdelval/gorealis/response"
|
"github.com/rdelval/gorealis/response"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
|
@ -44,7 +45,7 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
|
||||||
|
|
||||||
updateDetail := response.JobUpdateDetails(respDetail)
|
updateDetail := response.JobUpdateDetails(respDetail)
|
||||||
|
|
||||||
if(len(updateDetail) == 0 ) {
|
if len(updateDetail) == 0 {
|
||||||
fmt.Println("No update found")
|
fmt.Println("No update found")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -71,19 +72,18 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, timeout int) bool {
|
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, timeout int) (bool, error) {
|
||||||
|
|
||||||
for i := 0; i*interval < timeout; i++ {
|
for i := 0; i*interval < timeout; i++ {
|
||||||
|
|
||||||
live, err := m.Client.GetInstanceIds(key, aurora.LIVE_STATES)
|
live, err := m.Client.GetInstanceIds(key, aurora.LIVE_STATES)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return false, errors.Wrap(err, "Unable to communicate with Aurora")
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(live) == int(instances) {
|
if len(live) == int(instances) {
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Polling, instances running: ", len(live))
|
fmt.Println("Polling, instances running: ", len(live))
|
||||||
|
@ -91,5 +91,5 @@ func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, t
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Timed out")
|
fmt.Println("Timed out")
|
||||||
return false
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue