Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #350 from bianjieai/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
ka1fe1 authored Jan 4, 2024
2 parents 64ce5c9 + 21fbb8d commit 5989b4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/app/task/ibc_chain_config_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions internal/app/utils/time.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}()
Expand Down

0 comments on commit 5989b4f

Please sign in to comment.