forked from engineering/cloudservices
fixes to storage calculation resource consumption
parent
d14bee905d
commit
3e4171e0c4
|
@ -8,7 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
@ -83,20 +82,18 @@ func handler(config ConfigStruct) {
|
||||||
cur, err := collection.Find(context.TODO(), bson.D{})
|
cur, err := collection.Find(context.TODO(), bson.D{})
|
||||||
HandleError(err, 0)
|
HandleError(err, 0)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
for cur.Next(context.TODO()) {
|
for cur.Next(context.TODO()) {
|
||||||
wg.Add(1)
|
checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String())
|
||||||
go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String(), &wg)
|
|
||||||
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(10 * time.Second)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
err = mongoClient.Disconnect(ctx)
|
err = mongoClient.Disconnect(ctx)
|
||||||
HandleError(err, 1)
|
HandleError(err, 1)
|
||||||
fmt.Println("CSD-GO-STR finished, exiting with code 0. [GO]")
|
fmt.Println("CSD-GO-STR finished, exiting with code 0. [GO]")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkAccountSizeAndUpdate(username string, id string, wg *sync.WaitGroup) {
|
func checkAccountSizeAndUpdate(username string, id string) {
|
||||||
var size float64 = 0
|
var size float64 = 0
|
||||||
var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1)
|
var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1)
|
||||||
usernameFormat := strings.Replace(username, "\"", "", -1)
|
usernameFormat := strings.Replace(username, "\"", "", -1)
|
||||||
|
@ -108,5 +105,4 @@ func checkAccountSizeAndUpdate(username string, id string, wg *sync.WaitGroup) {
|
||||||
fmt.Println(status.Err())
|
fmt.Println(status.Err())
|
||||||
}
|
}
|
||||||
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f [GO]\n", string(username), string(id), size)
|
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f [GO]\n", string(username), string(id), size)
|
||||||
wg.Done()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ export default async function storage(client: Client) {
|
||||||
client.signale.log(`CSD-GO-STR Daemon exited with code ${code}.`);
|
client.signale.log(`CSD-GO-STR Daemon exited with code ${code}.`);
|
||||||
storageDaemon.removeAllListeners();
|
storageDaemon.removeAllListeners();
|
||||||
client.signale.info(`Reactivating CSD-GO-STR daemon startup interval. Reactivating in ${intervalTiming / 60000}min.`);
|
client.signale.info(`Reactivating CSD-GO-STR daemon startup interval. Reactivating in ${intervalTiming / 60000}min.`);
|
||||||
|
storageDaemon.kill();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/* let storageGo = spawn(`${__dirname}/../bin/storage`, [], { cwd: __dirname });
|
/* let storageGo = spawn(`${__dirname}/../bin/storage`, [], { cwd: __dirname });
|
||||||
|
|
Loading…
Reference in New Issue