1
0
Fork 0
refactor/models
Matthew 2019-12-19 00:02:59 -05:00
parent 338f880bd4
commit de6ed2d37f
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 9 additions and 4 deletions

View File

@ -51,7 +51,8 @@ func main() {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
HandleError(err, 1)
err = client.Ping(context.TODO(), nil)
err = client.Ping(context.TODO(), nil)
fmt.Printf("Connected to MongoDB [GO]\n")
HandleError(err, 1)
RedisClient = redis.NewClient(&redis.Options{
@ -60,11 +61,13 @@ func main() {
DB: 0,
})
_, err = RedisClient.Ping().Result()
_, err = RedisClient.Ping().Result()
fmt.Printf("Connected to Redis [GO]\n")
HandleError(err, 1)
for {
handler()
fmt.Printf("Calling handler func [GO]\n")
time.Sleep(1000000 * time.Second)
}
}
@ -74,7 +77,8 @@ func handler() {
HandleError(err, 0)
for cur.Next(context.TODO()) {
go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String())
go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String())
fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String())
time.Sleep(600000 * time.Second)
}
}
@ -85,5 +89,6 @@ func checkAccountSizeAndUpdate(username string, id string) {
bytes += sizeHome
sizeMail := DirSize("/var/mail/" + username)
bytes += sizeMail
RedisClient.Set("storage"+"-"+id, bytes, 0)
RedisClient.Set("storage"+"-"+id, bytes, 0)
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n", username, id, bytes)
}