mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-26 17:49:15 +01:00
重构msg的包
This commit is contained in:
39
backend/services/msg_handler/msg_system_info.go
Normal file
39
backend/services/msg_handler/msg_system_info.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package msg_handler
|
||||
|
||||
import (
|
||||
"crawlab/constants"
|
||||
"crawlab/database"
|
||||
"crawlab/model"
|
||||
"crawlab/utils"
|
||||
"encoding/json"
|
||||
"github.com/apex/log"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
type SystemInfo struct {
|
||||
msg NodeMessage
|
||||
}
|
||||
|
||||
func (s *SystemInfo) Handle() error {
|
||||
// 获取环境信息
|
||||
sysInfo, err := model.GetLocalSystemInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msgSd := NodeMessage{
|
||||
Type: constants.MsgTypeGetSystemInfo,
|
||||
NodeId: s.msg.NodeId,
|
||||
SysInfo: sysInfo,
|
||||
}
|
||||
msgSdBytes, err := json.Marshal(&msgSd)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
debug.PrintStack()
|
||||
return err
|
||||
}
|
||||
if _, err := database.RedisClient.Publish("nodes:master", utils.BytesToString(msgSdBytes)); err != nil {
|
||||
log.Errorf(err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user