| | |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/constvar" |
| | | "apsClient/crontask" |
| | | "apsClient/model" |
| | | "apsClient/nsq" |
| | |
| | | "apsClient/pkg/sqlitex" |
| | | "apsClient/router" |
| | | "apsClient/serf" |
| | | "apsClient/service" |
| | | "apsClient/service/plc_address" |
| | | "fmt" |
| | | "log" |
| | |
| | | return |
| | | } |
| | | |
| | | //从文件里读取当前生产设备id |
| | | conf.Conf.CurrentDeviceID = service.ReadDeviceIDFromFile() |
| | | if conf.Conf.CurrentDeviceID == "" { |
| | | conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId |
| | | } |
| | | |
| | | // 判断当前集群状态 |
| | | logx.Infof("current agent.ClusterStatus:%v", agent.ClusterStatus) |
| | | log.Println("current agent.ClusterStatus:", agent.ClusterStatus) |
| | | |
| | | conf.Conf.SerfClusterStatus = agent.ClusterStatus |
| | | |
| | | if agent.ClusterStatus != "slave" { |
| | | if err := nsq.Init(); err != nil { |
| | | logx.Errorf("nsq Init err:%v", err) |
| | |
| | | } |
| | | |
| | | func serfClusterEvent(stat int) { |
| | | ChangeClusterStatus(stat) |
| | | switch stat { |
| | | case serf.EventCreateCluster, serf.EventSlave2Master, serf.EventLeaveCluster: |
| | | if err := nsq.Init(); err != nil { //开启nsq |
| | |
| | | |
| | | logx.Infof("serf cluster event: %v", stat) |
| | | } |
| | | |
| | | func ChangeClusterStatus(stat int) { |
| | | switch stat { |
| | | case serf.EventSlave2Master, serf.EventCreateCluster: |
| | | conf.Conf.SerfClusterStatus = constvar.SerfClusterStatusMaster |
| | | case serf.EventLeaveCluster: |
| | | conf.Conf.SerfClusterStatus = constvar.SerfClusterStatusNull |
| | | case serf.EventJoinCluster, serf.EventMaster2Slave: |
| | | conf.Conf.SerfClusterStatus = constvar.SerfClusterStatusSlave |
| | | } |
| | | } |