This commit is contained in:
shoopea 2020-01-16 17:14:37 +08:00
parent 31a515a74c
commit 7c5ce72d33
2 changed files with 13 additions and 5 deletions

View File

@ -57,10 +57,6 @@ func getLockedRandomClient() (*ChirpClient, error) {
func setClientBusy(userID64 int64, from time.Time, duration time.Duration) error {
if clt, ok := getLockedClient(userID64, false); ok {
t := time.Now().UTC()
log.Printf("setClientBusy[%s] : now %s.\n", clt.Login, t.UTC().Format(timeFmt))
log.Printf("setClientBusy[%s] : from %s.\n", clt.Login, from.UTC().Format(timeFmt))
log.Printf("setClientBusy[%s] : for %s.\n", clt.Login, duration.String())
log.Printf("setClientBusy[%s] : until %s.\n", clt.Login, from.UTC().Add(duration).Format(timeFmt))
if from.UTC().Add(duration).After(time.Now().UTC()) {
clt.CWIdle = false
clt.CWBusyUntil = from.UTC().Add(duration)

14
cron.go
View File

@ -6,6 +6,7 @@ import (
"time"
//"github.com/robfig/cron/v3"
"github.com/tidwall/pretty"
"gopkg.in/robfig/cron.v3"
)
@ -98,6 +99,17 @@ func cronSaveClients() {
b, err := json.Marshal(clts)
logOnError(err, "cronSaveClients : Marshal")
log.Printf("cronSaveClients : %s\n", string(b))
pb := pretty.Pretty(b)
log.Printf("cronSaveClients :\n%s\n", string(pb))
err = ioutil.WriteFile("./clients_new.json", pb, 0644)
logOnError(err, "cronSaveClients : WriteFile")
err = os.Remove("./clients.json")
logOnError(err, "cronSaveClients : Remove")
err = os.Rename("./clients_new.json", "./clients.json")
logOnError(err, "cronSaveClients : Rename")
}