test
This commit is contained in:
parent
c483922063
commit
0a84246a26
|
@ -1,4 +1,5 @@
|
||||||
ChirpNestBot
|
ChirpNestBot
|
||||||
|
- [ ] MQTGCmdWorker[2] : Publishing message.: Exception (504) Reason: "channel/connection is not open" (add check in MQKeepAliveWorker ?)
|
||||||
- [ ] Make sure refresh message receives the message later (jobMsgRefresh)
|
- [ ] Make sure refresh message receives the message later (jobMsgRefresh)
|
||||||
- [ ] Adjust /time clock for auctions/... (delay between cw and real time ?)
|
- [ ] Adjust /time clock for auctions/... (delay between cw and real time ?)
|
||||||
- [ ] Update old auctions with client
|
- [ ] Update old auctions with client
|
||||||
|
|
3
main.go
3
main.go
|
@ -60,10 +60,10 @@ var (
|
||||||
JobQueue chan Job
|
JobQueue chan Job
|
||||||
|
|
||||||
msgParsingRules map[int]MessageParsingRule
|
msgParsingRules map[int]MessageParsingRule
|
||||||
clientsKeepAlive map[int64]*MQKeepAlive
|
|
||||||
clientsQueue map[int64]*MQClient
|
clientsQueue map[int64]*MQClient
|
||||||
|
|
||||||
clientsCW *sync.Map
|
clientsCW *sync.Map
|
||||||
|
clientsKeepAlive *sync.Map
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrintText(m *tb.Message) {
|
func PrintText(m *tb.Message) {
|
||||||
|
@ -156,6 +156,7 @@ func main() {
|
||||||
clientsQueue = make(map[int64]*MQClient)
|
clientsQueue = make(map[int64]*MQClient)
|
||||||
clientsKeepAlive = make(map[int64]*MQKeepAlive)
|
clientsKeepAlive = make(map[int64]*MQKeepAlive)
|
||||||
clientsCW = new(sync.Map)
|
clientsCW = new(sync.Map)
|
||||||
|
clientsKeepAlive = new(sync.Map)
|
||||||
|
|
||||||
for w := 1; w <= MQGetMsgWorkers; w++ {
|
for w := 1; w <= MQGetMsgWorkers; w++ {
|
||||||
go MQGetMsgWorker(w, MQCWMsgQueue)
|
go MQGetMsgWorker(w, MQCWMsgQueue)
|
||||||
|
|
15
workers.go
15
workers.go
|
@ -322,7 +322,7 @@ func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) {
|
||||||
func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
|
func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
|
||||||
//log.Printf("MQTGCmdWorker[" + strconv.Itoa(id) + "] : Starting.")
|
//log.Printf("MQTGCmdWorker[" + strconv.Itoa(id) + "] : Starting.")
|
||||||
for c := range cmds {
|
for c := range cmds {
|
||||||
if _, ok := clientsKeepAlive[c.FromUserID64]; ok {
|
if _, ok := clientsKeepAlive.Load(c.FromUserID64); ok {
|
||||||
j, err := json.Marshal(c)
|
j, err := json.Marshal(c)
|
||||||
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
|
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
|
||||||
//log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
|
//log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
|
||||||
|
@ -382,10 +382,11 @@ func MQKeepAliveWorker() {
|
||||||
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))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if x.Date.Add(time.Minute).Before(time.Now()) {
|
if x.Date.Add(10 * time.Second).Before(time.Now()) {
|
||||||
// outdated keep-alive
|
// outdated keep-alive coming from client
|
||||||
} else if _, ok := clientsKeepAlive[x.UserID64]; ok {
|
} else if v, ok := clientsKeepAlive.Load(x.UserID64); ok {
|
||||||
clientsKeepAlive[x.UserID64].Date = x.Date
|
k := v.(MQKeepAlive)
|
||||||
|
k.Date = x.Date
|
||||||
} else {
|
} else {
|
||||||
clt := MQClient{}
|
clt := MQClient{}
|
||||||
clt.Connection, err = amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + x.Queue)
|
clt.Connection, err = amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + x.Queue)
|
||||||
|
@ -401,7 +402,7 @@ func MQKeepAliveWorker() {
|
||||||
nil, // arguments
|
nil, // arguments
|
||||||
)
|
)
|
||||||
logOnError(err, "MQKeepAliveWorker : Failed to declare a queue")
|
logOnError(err, "MQKeepAliveWorker : Failed to declare a queue")
|
||||||
clientsKeepAlive[x.UserID64] = &x
|
clientsKeepAlive.Load(x.UserID64, &x)
|
||||||
clientsQueue[x.UserID64] = &clt
|
clientsQueue[x.UserID64] = &clt
|
||||||
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
|
@ -460,7 +461,7 @@ func MQTidyKeepAliveWorker() {
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
|
||||||
delete(clientsKeepAlive, v.UserID64)
|
clientsKeepAlive.Delete(v.UserID64)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user