From 6766c5a22b9fa765754ab222303f0c8397156c60 Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 16 May 2019 10:16:35 +0800 Subject: [PATCH] test --- def.go | 3 ++- main.go | 5 +++++ workers.go | 11 ++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/def.go b/def.go index b26c8b0..3258b3c 100644 --- a/def.go +++ b/def.go @@ -6,7 +6,7 @@ import ( "time" ) -type ChatWarsCommand struct { +type TGCommand struct { Type int64 `json:"type"` FromChatID64 int64 `json:"from_chat_id"` FromUserID64 int64 `json:"from_user_id"` @@ -183,6 +183,7 @@ const ( SQLCWMsgWorkers = 6 SQLIdentifyMsgWorkers = 6 SQLJobWorkers = 3 + TGCmdWorkers = 3 SQLJobSliceSize = 25 ) diff --git a/main.go b/main.go index a6bddd8..9f87dbc 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ var ( cfg Config MQCWMsgQueue chan ChatWarsMessage SQLMsgIdentifyQueue chan int64 + TGMsgQueue chan TGCommand msgParsingRules map[int]MessageParsingRule ) @@ -103,6 +104,7 @@ func main() { MQCWMsgQueue = make(chan ChatWarsMessage, 100) SQLMsgIdentifyQueue = make(chan int64, 100) + TGCmdQueue = make(chan TGCommand, 100) for w := 1; w <= MQGetMsgWorkers; w++ { go MQGetMsgWorker(w, MQCWMsgQueue) @@ -116,6 +118,9 @@ func main() { for w := 1; w <= SQLJobWorkers; w++ { go SQLJobWorker(w) } + for w := 1; w <= TGCmdWorkers; w++ { + go TGCmdWorker(w, b, TGCmdQueue) + } log.Println("Bot started !") diff --git a/workers.go b/workers.go index 4aae7b0..b460c9f 100644 --- a/workers.go +++ b/workers.go @@ -176,6 +176,11 @@ func SQLJobWorker(id int) { log.Printf("SQLJobWorker[" + strconv.Itoa(id) + "] : Closing.") } -/* -func BotMsgWorker(id int, botMsg <-chan -*/ +func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) { + log.Printf("TGCmdWorker[" + strconv.Itoa(id) + "] : Starting.") + for c := range cmds { + b, err := json.Marshal(c) + log.Printf("TGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(b)) + } + log.Printf("TGCmdWorker[" + strconv.Itoa(id) + "] : Closing.") +}