test
This commit is contained in:
parent
92c47a28ee
commit
c94c8efd46
28
client.go
28
client.go
|
@ -4,6 +4,34 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func clientKeepAlive(k, v interface{}) bool {
|
||||||
|
c := v.(MQKeepAlive)
|
||||||
|
if c.Date.Add(2 * KeepAliveHeartBeatSeconds * time.Second).Before(time.Now()) {
|
||||||
|
msgs, err := clientsQueue[v.UserID64].Channel.QueuePurge(clientsQueue[v.UserID64].Queue.Name, false)
|
||||||
|
logOnError(err, "clientKeepAlive : Channel.QueuePurge()")
|
||||||
|
err = clientsQueue[v.UserID64].Channel.Close()
|
||||||
|
logOnError(err, "clientKeepAlive : Channel.Close()")
|
||||||
|
err = clientsQueue[v.UserID64].Connection.Close()
|
||||||
|
logOnError(err, "clientKeepAlive : Connection.Close()")
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandSendMsg,
|
||||||
|
ToUserID64: v.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).", v.Nickname, msgs),
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
|
||||||
|
clientsKeepAlive.Delete(c.UserID64)
|
||||||
|
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func clientSendCWMsg(userID64 int64, s string) {
|
func clientSendCWMsg(userID64 int64, s string) {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandSendMsg,
|
Type: commandSendMsg,
|
||||||
|
|
1
def.go
1
def.go
|
@ -396,6 +396,7 @@ const (
|
||||||
MQTGCmdWorkers = 3
|
MQTGCmdWorkers = 3
|
||||||
MQTGCmdQueueSize = 100
|
MQTGCmdQueueSize = 100
|
||||||
SQLJobSliceSize = 25
|
SQLJobSliceSize = 25
|
||||||
|
KeepAliveHeartBeatSeconds = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
26
workers.go
26
workers.go
|
@ -440,31 +440,7 @@ func MQTidyKeepAliveWorker() {
|
||||||
//log.Printf("MQTidyKeepAliveWorker : Starting.")
|
//log.Printf("MQTidyKeepAliveWorker : Starting.")
|
||||||
for true {
|
for true {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
for _, v := range clientsKeepAlive {
|
clientsKeepAlive.Range(clientKeepAlive)
|
||||||
if v.Date.Add(90 * time.Second).Before(time.Now()) {
|
|
||||||
msgs, err := clientsQueue[v.UserID64].Channel.QueuePurge(clientsQueue[v.UserID64].Queue.Name, false)
|
|
||||||
logOnError(err, "MQTidyKeepAliveWorker : Channel.QueuePurge()")
|
|
||||||
err = clientsQueue[v.UserID64].Channel.Close()
|
|
||||||
logOnError(err, "MQTidyKeepAliveWorker : Channel.Close()")
|
|
||||||
err = clientsQueue[v.UserID64].Connection.Close()
|
|
||||||
logOnError(err, "MQTidyKeepAliveWorker : Connection.Close()")
|
|
||||||
c := TGCommand{
|
|
||||||
Type: commandSendMsg,
|
|
||||||
ToUserID64: v.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).", v.Nickname, msgs),
|
|
||||||
}
|
|
||||||
TGCmdQueue <- c
|
|
||||||
|
|
||||||
clientsKeepAlive.Delete(v.UserID64)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time.Sleep(time.Until(t.Add(time.Second)))
|
time.Sleep(time.Until(t.Add(time.Second)))
|
||||||
}
|
}
|
||||||
log.Printf("MQTidyKeepAliveWorker : Closing.")
|
log.Printf("MQTidyKeepAliveWorker : Closing.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user