From 2ea23e2364f742f528fb8b97657212c174d1bbd7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 21 十月 2023 14:06:59 +0800
Subject: [PATCH] 增加切换serf状态接口(调试用)
---
api/v1/plc.go | 41 +++++++++++++++++++++++++++++++++++++++++
router/index.go | 1 +
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/api/v1/plc.go b/api/v1/plc.go
index 85624bd..cc16206 100644
--- a/api/v1/plc.go
+++ b/api/v1/plc.go
@@ -3,13 +3,16 @@
import (
"apsClient/conf"
"apsClient/constvar"
+ "apsClient/crontask"
"apsClient/model/request"
"apsClient/model/response"
_ "apsClient/model/response"
+ "apsClient/nsq"
"apsClient/pkg/contextx"
"apsClient/pkg/ecode"
"apsClient/pkg/logx"
"apsClient/pkg/plc/apacheplc4x"
+ "apsClient/serf"
"apsClient/service"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
@@ -66,6 +69,44 @@
ctx.Ok()
}
+// SetSerfEvent
+// @Tags 鐢熶骇鏁伴噺
+// @Summary 璁剧疆鐢熶骇鎬婚噺
+// @Produce application/json
+// @Success 200 {object} contextx.Response{data=response.ProductProgress} "鎴愬姛"
+// @Router /v1/plc/setSerfEvent [post]
+func (slf *PlcApi) SetSerfEvent(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+ status := c.Query("status")
+ stat := cast.ToInt(status)
+ switch stat {
+ case serf.EventCreateCluster, serf.EventSlave2Master, serf.EventLeaveCluster:
+ if err := nsq.Init(); err != nil { //寮�鍚痭sq
+ logx.Errorf("nsq Init err:%v", err)
+ return
+ }
+ crontask.Once(true)
+ if err := crontask.RestartTask(true); err != nil { //浠aster鏂瑰紡閲嶅惎task
+ logx.Errorf("crontab task Init err:%v", err)
+ return
+ }
+ case serf.EventJoinCluster, serf.EventMaster2Slave:
+ nsq.Stop() //鍏抽棴nsq
+ crontask.Once(false)
+ if err := crontask.RestartTask(false); err != nil { //浠ラ潪master鏂瑰紡閲嶅惎task
+ logx.Errorf("crontab task Init err:%v", err)
+ return
+ }
+ }
+
+ logx.Infof("serf cluster event: %v", stat)
+
+ ctx.Ok()
+}
+
// GetProductProgressRealTime
// @Tags 鐢熶骇鏁伴噺
// @Summary 瀹炴椂鑾峰彇鐢熶骇杩涘害
diff --git a/router/index.go b/router/index.go
index 8a26e61..30ff8ae 100644
--- a/router/index.go
+++ b/router/index.go
@@ -58,6 +58,7 @@
plcGroup.POST("productProgress", plcApi.GetProductProgress) // 鑾峰彇鐢熶骇杩涘害
//plcGroup.POST("productProgressRealTime", plcApi.GetProductProgressRealTime) // 瀹炴椂鑾峰彇鐢熶骇杩涘害
plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 涓嬪彂鐢熶骇鎬婚噺
+ plcGroup.POST("setSerfEvent", plcApi.SetSerfEvent) // 涓嬪彂鐢熶骇鎬婚噺
}
processModelApi := new(v1.ProcessModelApi)
--
Gitblit v1.8.0