Files

37 lines
684 B
Go
Raw Permalink Normal View History

2025-10-13 11:27:38 +08:00
package task
import (
"context"
2026-02-01 15:25:55 +08:00
"fmt"
2025-10-13 11:27:38 +08:00
"time"
"github.com/spf13/cast"
2026-02-01 15:25:55 +08:00
"github.com/v03413/bepusdt/app/log"
2025-10-13 11:27:38 +08:00
"github.com/v03413/bepusdt/app/model"
)
func init() {
var rate = Rate{}
Register(Task{Duration: time.Second * 5, Callback: rate.Sync})
}
type Rate struct {
}
func (Rate) Sync(ctx context.Context) {
var lastAt model.Rate
model.Db.Model(&lastAt).Order("id desc").Limit(1).Find(&lastAt)
2025-10-13 11:27:38 +08:00
var interval = cast.ToInt64(model.GetC(model.RateSyncInterval))
if lastAt.ID != 0 && time.Now().Unix()-lastAt.CreatedAt.Time().Unix() < interval {
return
}
2026-02-01 15:25:55 +08:00
err := model.CoingeckoRate()
if err != nil {
log.Warn(fmt.Sprintf("同步汇率失败: %s", err.Error()))
}
2025-10-13 11:27:38 +08:00
}