diff --git a/Makefile b/Makefile deleted file mode 100644 index 2cf60ba..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -OUTPUT_BINARY_NAME = "scanner" -OUTPUT_DIR_NAME = "scanner" - - -ASSETS_DIR_NAME = "assets" -BUILD_DIR = "../../build" - -build: - go build -o ${BUILD_DIR}/${OUTPUT_DIR_NAME}/${OUTPUT_BINARY_NAME}${OUTPUT_BINARY_EXT} - @if [ -d ${ASSETS_DIR_NAME} ] && [ -n "`ls -A ${ASSETS_DIR_NAME}`" ] ;then \ - cp -r ${ASSETS_DIR_NAME}/* ${BUILD_DIR}/${OUTPUT_DIR_NAME}/; \ - fi - -clean: - rm -f ${BUILD_DIR}/${OUTPUT_DIR_NAME}/${OUTPUT_BINARY_NAME} \ No newline at end of file diff --git a/internal/event/agent_check_state.go b/internal/event/agent_check_state.go index 1471db3..1b17d4b 100644 --- a/internal/event/agent_check_state.go +++ b/internal/event/agent_check_state.go @@ -66,8 +66,8 @@ func (t *AgentCheckState) Execute(execCtx ExecuteContext) { // 检查上次上报时间,超时的设置为不可用 // TODO 没有上报过是否要特殊处理? - if node.LastReportTime == nil && time.Since(*node.LastReportTime) > time.Duration(config.Cfg().NodeUnavailableSeconds)*time.Second { - err := execCtx.Args.DB.Node().ChangeState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_UNAVAILABLE) + if node.LastReportTime != nil && time.Since(*node.LastReportTime) > time.Duration(config.Cfg().NodeUnavailableSeconds)*time.Second { + err := execCtx.Args.DB.Node().UpdateState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_UNAVAILABLE) if err != nil { log.WithField("NodeID", t.NodeID).Warnf("set node state failed, err: %s", err.Error()) return @@ -104,7 +104,7 @@ func (t *AgentCheckState) Execute(execCtx ExecuteContext) { if getResp.Body.IPFSState != consts.IPFS_STATE_OK { log.WithField("NodeID", t.NodeID).Warnf("IPFS status is %s, set node state unavailable", getResp.Body.IPFSState) - err := execCtx.Args.DB.Node().ChangeState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_UNAVAILABLE) + err := execCtx.Args.DB.Node().UpdateState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_UNAVAILABLE) if err != nil { log.WithField("NodeID", t.NodeID).Warnf("change node state failed, err: %s", err.Error()) } @@ -112,7 +112,7 @@ func (t *AgentCheckState) Execute(execCtx ExecuteContext) { } // TODO 如果以后还有其他的状态,要判断哪些状态下能设置Normal - err = execCtx.Args.DB.Node().ChangeState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_NORMAL) + err = execCtx.Args.DB.Node().UpdateState(execCtx.Args.DB.SQLCtx(), t.NodeID, consts.NODE_STATE_NORMAL) if err != nil { log.WithField("NodeID", t.NodeID).Warnf("change node state failed, err: %s", err.Error()) } diff --git a/magefiles/magefile.go b/magefiles/magefile.go new file mode 100644 index 0000000..f146a71 --- /dev/null +++ b/magefiles/magefile.go @@ -0,0 +1,22 @@ +//go:build mage + +package main + +import ( + "magefiles" + "magefiles/utils" + + //mage:import + "magefiles/targets" +) + +var Default = Build + +func Build() error { + return utils.Build(magefiles.BuildArgs{ + OutputBinName: "scanner", + OutputDirName: "scanner", + AssetsDir: "assets", + PubArgs: targets.PubGoBuildArgs, + }) +} diff --git a/main.go b/main.go index 8c2b256..de7d256 100644 --- a/main.go +++ b/main.go @@ -109,15 +109,17 @@ func serveDistLock(svc *distlocksvc.Service, wg *sync.WaitGroup) { func startTickEvent(tickExecutor *tickevent.Executor) { // TODO 可以考虑增加配置文件,配置这些任务间隔时间 - tickExecutor.Start(tickevent.NewBatchAllAgentCheckCache(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + interval := 5 * 60 * 1000 - tickExecutor.Start(tickevent.NewBatchCheckAllObject(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + tickExecutor.Start(tickevent.NewBatchAllAgentCheckCache(), interval, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) - tickExecutor.Start(tickevent.NewBatchCheckAllRepCount(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + tickExecutor.Start(tickevent.NewBatchCheckAllObject(), interval, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) - tickExecutor.Start(tickevent.NewBatchCheckAllStorage(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + tickExecutor.Start(tickevent.NewBatchCheckAllRepCount(), interval, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) - //tickExecutor.Start(tickevent.NewCheckAgentState(), 5*60*1000, tickevent.StartOption{RandomFirstStartDelayMs: 60 * 1000}) + tickExecutor.Start(tickevent.NewBatchCheckAllStorage(), interval, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) - tickExecutor.Start(tickevent.NewCheckCache(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + tickExecutor.Start(tickevent.NewCheckAgentState(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) + + tickExecutor.Start(tickevent.NewCheckCache(), interval, tickevent.StartOption{RandomStartDelayMs: 60 * 1000}) }