File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
33import (
44 "fmt"
55 "github.com/sirupsen/logrus"
6+ "math/rand"
67 "sync"
78)
89
@@ -90,18 +91,17 @@ func (d *Dispatcher) selectInstance(adamId string) *DecryptInstance {
9091 }
9192 }
9293
93- var oldestInstance * DecryptInstance
94+ var candidates [] * DecryptInstance
9495
9596 for _ , inst := range d .Instances {
96- if ! checkAvailableOnRegion (adamId , inst .region , false ) {
97- continue
97+ if checkAvailableOnRegion (adamId , inst .region , false ) {
98+ candidates = append ( candidates , inst )
9899 }
100+ }
99101
100- if oldestInstance == nil || inst .GetLastHandleTime ().Before (oldestInstance .GetLastHandleTime ()) {
101- // logrus.Debugf("selected instance %s for adamid %s, method 3", inst.id, adamId)
102- oldestInstance = inst
103- }
102+ if len (candidates ) > 0 {
103+ return candidates [rand .Intn (len (candidates ))]
104104 }
105105
106- return oldestInstance
106+ return nil
107107}
You can’t perform that action at this time.
0 commit comments