Added phased startup string function for bringing services back online gradually
This commit is contained in:
@@ -3,6 +3,7 @@ package global
|
|||||||
import (
|
import (
|
||||||
crand "crypto/rand" // Probably better than math/rand for this
|
crand "crypto/rand" // Probably better than math/rand for this
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateRandomString(length int) string {
|
func GenerateRandomString(length int) string {
|
||||||
@@ -23,3 +24,15 @@ func GenerateRandomString(length int) string {
|
|||||||
}
|
}
|
||||||
return string(charArray)
|
return string(charArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PhasedStartupString() string {
|
||||||
|
// Redis is used for a lot of stuff, which means the Postgres DB gets HAMMERED on a fresh startup. Use
|
||||||
|
// this to generate a shuffled string that can be used to only allow e.g. UIDs starting with [x] to connect
|
||||||
|
// for the first however many seconds and incrementally expand access so that data doesn't need to be loaded all at
|
||||||
|
// once
|
||||||
|
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
|
rand.Shuffle(len(chars), func(i, j int) {
|
||||||
|
chars[i], chars[j] = chars[j], chars[i]
|
||||||
|
})
|
||||||
|
return string(chars)
|
||||||
|
}
|
||||||
|
@@ -15,3 +15,7 @@ func TestGenerateRandomString(t *testing.T) {
|
|||||||
fmt.Println("Test: 30 chars")
|
fmt.Println("Test: 30 chars")
|
||||||
fmt.Println(GenerateRandomString(30))
|
fmt.Println(GenerateRandomString(30))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPhasedStartup(t *testing.T) {
|
||||||
|
fmt.Printf("%c", PhasedStartupString()[1])
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user