Skip to content

Commit 94c450c

Browse files
fix: randomly assign instance
1 parent f75eead commit 94c450c

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

decrypt.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
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
}

0 commit comments

Comments
 (0)