add lock on storage

merge-requests/2/merge
Matthew 2019-12-27 21:19:32 -05:00
parent 13faf9b4f9
commit f866592513
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 28 additions and 22 deletions

View File

@ -9,8 +9,8 @@ import (
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
"io/ioutil" "io/ioutil"
"time"
"strings" "strings"
"time"
) )
// Collection the MongoDB Account collection // Collection the MongoDB Account collection
@ -39,6 +39,7 @@ func HandleError(e error, serv int) {
} }
func main() { func main() {
var status bool
type Config struct { type Config struct {
MongoDB string `json:"mongoURL"` MongoDB string `json:"mongoURL"`
} }
@ -67,15 +68,19 @@ func main() {
_, err = RedisClient.Ping().Result() _, err = RedisClient.Ping().Result()
fmt.Printf("Connected to Redis [GO]\n") fmt.Printf("Connected to Redis [GO]\n")
HandleError(err, 1) HandleError(err, 1)
status = false
for { for {
fmt.Printf("Calling handler func [GO]\n") fmt.Printf("Calling handler func [GO]\n")
handler() if status == false {
handler(&status)
time.Sleep(1000000 * time.Millisecond) time.Sleep(1000000 * time.Millisecond)
} }
} }
}
func handler() { func handler(status* bool) {
*status = true
cur, err := Collection.Find(context.TODO(), bson.D{}) cur, err := Collection.Find(context.TODO(), bson.D{})
HandleError(err, 0) HandleError(err, 0)
@ -84,6 +89,7 @@ func handler() {
fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String()) fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String())
time.Sleep(600000 * time.Millisecond) time.Sleep(600000 * time.Millisecond)
} }
*status = false
} }
func checkAccountSizeAndUpdate(username string, id string) { func checkAccountSizeAndUpdate(username string, id string) {