diff --git a/internal/app/task/ibc_chain_config_task.go b/internal/app/task/ibc_chain_config_task.go index 866bde01..b0040f21 100644 --- a/internal/app/task/ibc_chain_config_task.go +++ b/internal/app/task/ibc_chain_config_task.go @@ -107,7 +107,7 @@ func (t *IbcChainConfigTask) getChainConf() ([]*entity.ChainConfig, error) { } // getIbcChannels 通过lcd channels_path 接口获取链上存在的所有channel信息 -func (t *IbcChainConfigTask) getIbcChannels(chain, lcd, apiPath string) ([]*entity.ChannelPath, error) { +func (t *IbcChainConfigTask) getIbcChannels(chain, lcd, originApiPath string) ([]*entity.ChannelPath, error) { if lcd == "" { logrus.Errorf("task %s %s getIbcChannels error, lcd error", t.Name(), chain) return nil, fmt.Errorf("lcd error") @@ -118,7 +118,7 @@ func (t *IbcChainConfigTask) getIbcChannels(chain, lcd, apiPath string) ([]*enti var channelPathList []*entity.ChannelPath for { - apiPath = strings.ReplaceAll(apiPath, replaceHolderOffset, strconv.Itoa(offset)) + apiPath := strings.ReplaceAll(originApiPath, replaceHolderOffset, strconv.Itoa(offset)) apiPath = strings.ReplaceAll(apiPath, replaceHolderLimit, strconv.Itoa(limit)) url := fmt.Sprintf("%s%s", lcd, apiPath) bz, err := utils.HttpGet(url) diff --git a/internal/app/utils/time.go b/internal/app/utils/time.go index cd547f04..0c684a13 100644 --- a/internal/app/utils/time.go +++ b/internal/app/utils/time.go @@ -1,19 +1,35 @@ package utils -import "time" +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) func RunTimer(num int, uint Unit, fn func()) { go func() { + sigChan := make(chan os.Signal, 1) // run once right now + // 捕获指定的系统信号 + signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + // 创建一个timer + t := time.NewTimer(time.Second * 5) fn() for { now := time.Now() next := now.Add(ParseDuration(num, uint)) next = TruncateTime(next, uint) - t := time.NewTimer(next.Sub(now)) + //使用 time.Reset 重置 timer,重复利用 timer + t.Reset(next.Sub(now)) select { case <-t.C: fn() + case <-sigChan: + t.Stop() + fmt.Println("timer is exist...") + return } } }()