This commit is contained in:
shoopea 2020-01-16 23:18:25 +08:00
parent ee47b8058b
commit 699a3d75a6
3 changed files with 15 additions and 10 deletions

View File

@ -32,8 +32,13 @@ func loadClients() error {
cx := ChirpClient{}
copier.Copy(&cx, &c)
cx.Active = false
/*
cx.MQ.Connection, err = amqp.Dial("amqp://" + cx.MQ.User + ":" + cx.MQ.Password + "@" + cx.MQ.Host + "/" + cx.MQ.Path)
logOnError(err, "loadClients : Failed to connect to RabbitMQ")
*/
clients[cx.TGUserID64] = &cx
log.Printf("loadClients[%s] : done\n", cx.Login)
}
muxClients.Unlock()

18
def.go
View File

@ -62,14 +62,14 @@ type ObjSubType struct {
}
type MQClient struct {
User string
Password string
Host string
Path string
SSL bool
Connection *amqp.Connection
Channel *amqp.Channel
Queue amqp.Queue
User string `json:"user"`
Password string `json:"passwd"`
Host string `json:"host"`
Path string `json:"path"`
SSL bool `json:"ssl"`
Connection *amqp.Connection `json:"-"`
Channel *amqp.Channel `json:"-"`
Queue amqp.Queue `json:"-"`
}
type ChirpClient struct {
@ -77,7 +77,7 @@ type ChirpClient struct {
Login string `json:"nickname"`
Active bool `json:"active"`
TGUserID64 int64 `json:"tg_user_id"`
MQ MQClient `json:"-"`
MQ MQClient `json:"mq"`
CWUserID64 int64 `json:"user_id"`
CWGuildID64 int64 `json:"guild_id"`
CWRole string `json:"role"`

View File

@ -252,7 +252,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
j, err := json.Marshal(c)
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
//log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
for clt.MQ.Connection.IsClosed() {
for clt.MQ.Connection == nil || clt.MQ.Connection.IsClosed() {
clt.Active = false
log.Printf("MQTGCmdWorker : Resetting MQ connection for #%d.\n", c.FromUserID64)
clt.MQ.Connection, err = amqp.Dial("amqp://" + clt.MQ.User + ":" + clt.MQ.Password + "@" + clt.MQ.Host + "/" + clt.MQ.Path)