From 3e37e5eb36566df8e6836b8b3ba588b5a93c6194 Mon Sep 17 00:00:00 2001 From: iostream1308 Date: Thu, 19 Dec 2024 14:22:20 +0700 Subject: [PATCH] add condition chainid and add fill-price-time-interval-flag --- v2/cmd/price_filler/main.go | 2 +- v2/pkg/app/price_filler.go | 7 +++++++ v2/pkg/price_filler/price_filler.go | 8 ++++---- v2/pkg/storage/promotees/storage.go | 11 ++++++----- v2/pkg/storage/promotees/storage_test.go | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/v2/cmd/price_filler/main.go b/v2/cmd/price_filler/main.go index e1f41f5..6b1a6de 100644 --- a/v2/cmd/price_filler/main.go +++ b/v2/cmd/price_filler/main.go @@ -80,7 +80,7 @@ func run(c *cli.Context) error { l.Errorw("Error while init price filler") return err } - priceFiller.Run() + priceFiller.Run(c.Int(libapp.FillPriceTimeIntervalFlag.Name)) return nil } diff --git a/v2/pkg/app/price_filler.go b/v2/pkg/app/price_filler.go index a5caadf..43c6392 100644 --- a/v2/pkg/app/price_filler.go +++ b/v2/pkg/app/price_filler.go @@ -13,15 +13,22 @@ var BinanceSecretKeyFlag = cli.StringFlag{ Name: "binance-secret-key", EnvVar: "BINANCE_SECRET_KEY", } + var MarkToMarketURLFlag = cli.StringFlag{ Name: "mark-to-market-url", EnvVar: "MARK_TO_MARKET_URL", } +var FillPriceTimeIntervalFlag = cli.StringFlag{ + Name: "fill-price-time-interval", + EnvVar: "FILL_PRICE_TIME_INTERVAL", +} + func PriceFillerFlags() []cli.Flag { return []cli.Flag{ BinanceAPIKeyFlag, BinanceSecretKeyFlag, MarkToMarketURLFlag, + FillPriceTimeIntervalFlag, } } diff --git a/v2/pkg/price_filler/price_filler.go b/v2/pkg/price_filler/price_filler.go index f7ce8bf..4b62c1d 100644 --- a/v2/pkg/price_filler/price_filler.go +++ b/v2/pkg/price_filler/price_filler.go @@ -86,9 +86,9 @@ func NewPriceFiller(l *zap.SugaredLogger, return p, nil } -func (p *PriceFiller) Run() { +func (p *PriceFiller) Run(fillPriceInterval int) { go p.runUpdateAllCoinInfoRoutine() - p.runBackFillTradelogPriceRoutine() + p.runBackFillTradelogPriceRoutine(fillPriceInterval) } func (p *PriceFiller) getPrice(token string, timestamp int64) (float64, error) { @@ -141,8 +141,8 @@ func (p *PriceFiller) runUpdateAllCoinInfoRoutine() { } } -func (p *PriceFiller) runBackFillTradelogPriceRoutine() { - ticker := time.NewTicker(backfillTradeLogsPriceInterval) +func (p *PriceFiller) runBackFillTradelogPriceRoutine(fillPriceInterval int) { + ticker := time.NewTicker(time.Duration(fillPriceInterval) * time.Minute) defer ticker.Stop() for ; ; <-ticker.C { diff --git a/v2/pkg/storage/promotees/storage.go b/v2/pkg/storage/promotees/storage.go index 047661b..8ea176d 100644 --- a/v2/pkg/storage/promotees/storage.go +++ b/v2/pkg/storage/promotees/storage.go @@ -131,20 +131,21 @@ func (s *Storage) InsertPromoterName(promotees []Promotee) error { func (s *Storage) CheckPromoteeExist(promotee string) (bool, error) { builder := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar). - Select(promoteesColumns()...). + Select("COUNT(*)"). From(promoteesTable). - Where(squirrel.Eq{"promotee": promotee}) + Where(squirrel.Eq{"promotee": promotee}). + Where(squirrel.Eq{"chain_id": "1"}) q, p, err := builder.ToSql() if err != nil { return false, err } - var promotees []Promotee - if err := s.db.Select(&promotees, q, p...); err != nil { + var count int + if err := s.db.Get(&count, q, p...); err != nil { return false, err } - if len(promotees) >= 1 { + if count >= 1 { return true, nil } return false, nil diff --git a/v2/pkg/storage/promotees/storage_test.go b/v2/pkg/storage/promotees/storage_test.go index 4d27656..1710e43 100644 --- a/v2/pkg/storage/promotees/storage_test.go +++ b/v2/pkg/storage/promotees/storage_test.go @@ -61,5 +61,5 @@ func TestInsert(t *testing.T) { } } - t.Log(s.CheckPromoteeExist("0xd1742b3c4fbb096990c8950fa635aec75b30781a")) + t.Log(s.CheckPromoteeExist("0x0b8a49d816cc709b6eadb09498030ae3416b66dc")) }