-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll_scale.go
executable file
·47 lines (38 loc) · 1.1 KB
/
poll_scale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package broker
import (
"errors"
"time"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/lager"
)
func (broker *SCSBroker) pollScale(proc ccv3.Process, desired int) (ccv3.Process, ccv3.Warnings, error) {
var allWarnings ccv3.Warnings
cfClient, err := broker.GetClient()
if err != nil {
return ccv3.Process{}, nil, errors.New("Couldn't start session: " + err.Error())
}
done := false
for !done {
time.Sleep(1000000000)
ready := 0
broker.Logger.Info("polling process instance states", lager.Data{
"process_guid": proc.GUID,
})
instances, warnings, err := cfClient.GetProcessInstances(proc.GUID)
broker.showWarnings(warnings, proc)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return ccv3.Process{}, allWarnings, err
}
for _, instance := range instances {
if instance.State == constant.ProcessInstanceRunning || instance.State == constant.ProcessInstanceCrashed {
ready += 1
}
}
if ready == desired {
done = true
}
}
return proc, allWarnings, nil
}