1 Star 0 Fork 0

JUMEI_ARCH/squirrel-worker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
message.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
iampastor 提交于 2017-05-05 10:15 . fix job finish send index
package main
import (
"encoding/binary"
"io"
)
const (
MT_SUBMIT_JOB = 1 + iota //从server提交过来的任务
MT_KILL_JOB
MT_JOB_RESULT //任务执行完成的返回
MT_QUERY_JOB
MT_EXECUTOR_IDENT
MT_STATUS_RESP
MT_QUERY_RESP
MT_SUBMIT_RESP
MT_HEARTBEAT
QUERY_EXTERNA_SHELL
MT_EXIT //程序退出消息
MT_LOG_SUBMIT //实时提交日志信息
MT_LOG_RESP = 21 //日志确认消息
STATUS_OK = 1
STATUS_FAIL = 2
STATUS_NO_JOB = 3
)
const PROTOCOL_VERSION = 1
//消息格式:4 byte(协议版本) + 4 byte(消息数据的长度) + 4 byte(消息的类型) + 消息数据
type MessageHeader struct {
Version uint32
Length uint32
Type uint32
}
type Message struct {
Type int
Body interface{}
}
type ExecutorIdent struct {
Id string `json:"id"`
MaxConcurrentJob int `json:"maxConcurrentJob"`
IDC string `json:"IDC"`
UUID string `json:"UUID"`
JobID string `json:"jobID"`
JobConf JobConf `json:"jobConf"`
SendIndex int32 `json:"sendIndex"`
}
func (this *MessageHeader) Encode() []byte {
//log.Debugf("encode header %+v", this)
buf := make([]byte, 12)
binary.BigEndian.PutUint32(buf, this.Version)
binary.BigEndian.PutUint32(buf[4:8], this.Length)
binary.BigEndian.PutUint32(buf[8:12], this.Type)
return buf
}
func (this *MessageHeader) Decode(reader io.Reader) error {
err := binary.Read(reader, binary.BigEndian, this)
//log.Debugf("decode header %+v", this)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/squirrel-worker.git
[email protected]:JMArch/squirrel-worker.git
JMArch
squirrel-worker
squirrel-worker
master

搜索帮助