This commit is contained in:
shoopea 2019-06-14 11:27:43 +08:00
parent 0be25f0899
commit c92d1867e3

View File

@ -1,33 +1,34 @@
package main package main
import ( import (
"fmt"
"strings" "strings"
"time" "time"
) )
func clientKeepAlive(k, v interface{}) bool { func clientKeepAlive(k, v interface{}) bool {
c := v.(MQKeepAlive) clt := v.(MQKeepAlive)
if c.Date.Add(2 * KeepAliveHeartBeatSeconds * time.Second).Before(time.Now()) { if clt.Date.Add(2 * KeepAliveHeartBeatSeconds * time.Second).Before(time.Now()) {
msgs, err := clientsQueue[c.UserID64].Channel.QueuePurge(clientsQueue[v.UserID64].Queue.Name, false) msgs, err := clientsQueue[clt.UserID64].Channel.QueuePurge(clientsQueue[clt.UserID64].Queue.Name, false)
logOnError(err, "clientKeepAlive : Channel.QueuePurge()") logOnError(err, "clientKeepAlive : Channel.QueuePurge()")
err = clientsQueue[c.UserID64].Channel.Close() err = clientsQueue[clt.UserID64].Channel.Close()
logOnError(err, "clientKeepAlive : Channel.Close()") logOnError(err, "clientKeepAlive : Channel.Close()")
err = clientsQueue[c.UserID64].Connection.Close() err = clientsQueue[clt.UserID64].Connection.Close()
logOnError(err, "clientKeepAlive : Connection.Close()") logOnError(err, "clientKeepAlive : Connection.Close()")
c := TGCommand{ c := TGCommand{
Type: commandSendMsg, Type: commandSendMsg,
ToUserID64: c.UserID64, ToUserID64: clt.UserID64,
Text: "Timeout, purging and closing command queue.", Text: "Timeout, purging and closing command queue.",
} }
TGCmdQueue <- c TGCmdQueue <- c
c = TGCommand{ c = TGCommand{
Type: commandSendMsg, Type: commandSendMsg,
ToUserID64: cfg.Bot.Admin, ToUserID64: cfg.Bot.Admin,
Text: fmt.Sprintf("Client %s timed out (%d messages purged).", c.Nickname, msgs), Text: fmt.Sprintf("Client %s timed out (%d messages purged).", clt.Nickname, msgs),
} }
TGCmdQueue <- c TGCmdQueue <- c
clientsKeepAlive.Delete(c.UserID64) clientsKeepAlive.Delete(clt.UserID64)
} }
return true return true