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
import (
"fmt"
"strings"
"time"
)
func clientKeepAlive(k, v interface{}) bool {
c := v.(MQKeepAlive)
if c.Date.Add(2 * KeepAliveHeartBeatSeconds * time.Second).Before(time.Now()) {
msgs, err := clientsQueue[c.UserID64].Channel.QueuePurge(clientsQueue[v.UserID64].Queue.Name, false)
clt := v.(MQKeepAlive)
if clt.Date.Add(2 * KeepAliveHeartBeatSeconds * time.Second).Before(time.Now()) {
msgs, err := clientsQueue[clt.UserID64].Channel.QueuePurge(clientsQueue[clt.UserID64].Queue.Name, false)
logOnError(err, "clientKeepAlive : Channel.QueuePurge()")
err = clientsQueue[c.UserID64].Channel.Close()
err = clientsQueue[clt.UserID64].Channel.Close()
logOnError(err, "clientKeepAlive : Channel.Close()")
err = clientsQueue[c.UserID64].Connection.Close()
err = clientsQueue[clt.UserID64].Connection.Close()
logOnError(err, "clientKeepAlive : Connection.Close()")
c := TGCommand{
Type: commandSendMsg,
ToUserID64: c.UserID64,
ToUserID64: clt.UserID64,
Text: "Timeout, purging and closing command queue.",
}
TGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
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
clientsKeepAlive.Delete(c.UserID64)
clientsKeepAlive.Delete(clt.UserID64)
}
return true