fix client revamping
This commit is contained in:
parent
c71bd20e5a
commit
c0cae8c491
23
workers.go
23
workers.go
@ -159,19 +159,18 @@ func MQKeepAliveWorker() {
|
|||||||
x := MQKeepAlive{}
|
x := MQKeepAlive{}
|
||||||
err = json.Unmarshal(d.Body, &x)
|
err = json.Unmarshal(d.Body, &x)
|
||||||
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
|
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
|
||||||
log.Printf("MQKeepAliveWorker : Received message :\n%s", string(d.Body))
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("MQKeepAliveWorker : Received message from %s (%d).\n", x.Nickname, x.TGUserID64)
|
//log.Printf("MQKeepAliveWorker : Received message from %s (%d).\n", x.Nickname, x.TGUserID64)
|
||||||
if x.Date.Add(10 * time.Second).Before(time.Now()) {
|
if x.Date.Add(10 * time.Second).Before(time.Now()) {
|
||||||
// outdated keep-alive coming from client
|
// outdated keep-alive coming from client
|
||||||
} else if clt, ok := getLockedClient(x.TGUserID64, true); ok {
|
} else if clt, ok := getLockedClient(x.TGUserID64, true); ok {
|
||||||
clt.HeartBeat = x.Date
|
clt.HeartBeat = x.Date
|
||||||
if clt.Active {
|
if clt.Active {
|
||||||
log.Printf("MQKeepAliveWorker : Client %s (%d) already active.\n", clt.Login, clt.TGUserID64)
|
//log.Printf("MQKeepAliveWorker : Client %s (%d) already active.\n", clt.Login, clt.TGUserID64)
|
||||||
clt.Mux.Unlock()
|
clt.Mux.Unlock()
|
||||||
} else {
|
} else {
|
||||||
clt.Login = x.Nickname
|
clt.Login = x.Nickname
|
||||||
log.Printf("MQKeepAliveWorker : Connecting to %s (%d).\n", clt.Login, clt.TGUserID64)
|
//log.Printf("MQKeepAliveWorker : Connecting to %s (%d).\n", clt.Login, clt.TGUserID64)
|
||||||
clt.MQ.User = cfg.Rabbit.User
|
clt.MQ.User = cfg.Rabbit.User
|
||||||
clt.MQ.Password = cfg.Rabbit.Password
|
clt.MQ.Password = cfg.Rabbit.Password
|
||||||
clt.MQ.Host = cfg.Rabbit.Host
|
clt.MQ.Host = cfg.Rabbit.Host
|
||||||
@ -202,12 +201,12 @@ func MQKeepAliveWorker() {
|
|||||||
clt.MQ.Connection.Close()
|
clt.MQ.Connection.Close()
|
||||||
} else {
|
} else {
|
||||||
clt.Active = true
|
clt.Active = true
|
||||||
log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname)
|
//log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clt.Mux.Unlock()
|
clt.Mux.Unlock()
|
||||||
|
if clt.Active {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandSendMsg,
|
Type: commandSendMsg,
|
||||||
ToUserID64: x.TGUserID64,
|
ToUserID64: x.TGUserID64,
|
||||||
@ -222,6 +221,14 @@ func MQKeepAliveWorker() {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
|
||||||
clientSendCWMsg(x.TGUserID64, `🏅Me`)
|
clientSendCWMsg(x.TGUserID64, `🏅Me`)
|
||||||
|
} else {
|
||||||
|
c = TGCommand{
|
||||||
|
Type: commandSendMsg,
|
||||||
|
ToUserID64: cfg.Bot.Admin,
|
||||||
|
Text: fmt.Sprintf("Cannot connect to client `%s`.", x.Nickname),
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -596,9 +603,9 @@ func MQTidyKeepAliveWorker() {
|
|||||||
TGCmdQueue <- cmd
|
TGCmdQueue <- cmd
|
||||||
clt.Active = false
|
clt.Active = false
|
||||||
} else if clt.Active {
|
} else if clt.Active {
|
||||||
log.Printf("MQTidyKeepAliveWorker : Client %s is active.\n", clt.Login)
|
//log.Printf("MQTidyKeepAliveWorker : Client %s is active.\n", clt.Login)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login)
|
//log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login)
|
||||||
}
|
}
|
||||||
clt.Mux.Unlock()
|
clt.Mux.Unlock()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user