Skip to content

Commit

Permalink
Merge branch 'dipdup-net:master' into feat/hasura-config
Browse files Browse the repository at this point in the history
  • Loading branch information
852Kerfunkle authored Apr 25, 2022
2 parents c8c388c + 05ab7f1 commit bae8333
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
58 changes: 40 additions & 18 deletions cmd/metadata/service/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (s *TokenService) manager(ctx context.Context) {
func (s *TokenService) saver(ctx context.Context) {
defer s.wg.Done()

ticker := time.NewTicker(time.Second * 10)
defer ticker.Stop()

tokens := make([]*models.TokenMetadata, 0)
for {
select {
Expand All @@ -162,34 +165,53 @@ func (s *TokenService) saver(ctx context.Context) {
continue
}

if err := s.repo.UpdateTokenMetadata(ctx, tokens); err != nil {
if err := s.bulkSaveTokens(ctx, tokens); err != nil {
log.Err(err).Msg("UpdateTokenMetadata")
continue
}

for i := range tokens {
s.queue.Delete(tokens[i].ID)

if s.prom != nil {
switch tokens[i].Status {
case models.StatusApplied, models.StatusFailed:
s.prom.DecGaugeValue("metadata_new", map[string]string{
"network": s.network,
"type": "token",
})
s.prom.IncrementCounter("metadata_counter", map[string]string{
"network": s.network,
"type": "token",
"status": tokens[i].Status.String(),
})
}
}
tokens = nil

case <-ticker.C:
if len(tokens) == 0 {
continue
}
if err := s.bulkSaveTokens(ctx, tokens); err != nil {
log.Err(err).Msg("UpdateTokenMetadata")
continue
}

tokens = nil
}
}
}

func (s *TokenService) bulkSaveTokens(ctx context.Context, tokens []*models.TokenMetadata) error {
if err := s.repo.UpdateTokenMetadata(ctx, tokens); err != nil {
return err
}

for i := range tokens {
s.queue.Delete(tokens[i].ID)

if s.prom != nil {
switch tokens[i].Status {
case models.StatusApplied, models.StatusFailed:
s.prom.DecGaugeValue("metadata_new", map[string]string{
"network": s.network,
"type": "token",
})
s.prom.IncrementCounter("metadata_counter", map[string]string{
"network": s.network,
"type": "token",
"status": tokens[i].Status.String(),
})
}
}
}
return nil
}

func (s *TokenService) worker(ctx context.Context) {
defer s.wg.Done()

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/dipdup-net/go-lib v0.1.56 h1:Jr0+lDCaOc9Y9XfKoi1F22peVaB1mZe5XsIJKg5mUHk=
github.com/dipdup-net/go-lib v0.1.56/go.mod h1:ZOAyo2sqNLCCVdvHvPbiWfgImvmrMW7/sdQiSsGrD44=
github.com/dipdup-net/go-lib v0.2.0 h1:RGreU/ydxeaU5Eyad1g1NF44uMpgqVR6kgmY+2Imvg0=
github.com/dipdup-net/go-lib v0.2.0/go.mod h1:ZOAyo2sqNLCCVdvHvPbiWfgImvmrMW7/sdQiSsGrD44=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
Expand Down Expand Up @@ -215,7 +213,6 @@ github.com/ipfs/go-ipfs-files v0.0.9/go.mod h1:aFv2uQ/qxWpL/6lidWvnSQmaVqCrf0TBG
github.com/ipfs/go-ipfs-files v0.1.1 h1:/MbEowmpLo9PJTEQk16m9rKzUHjeP4KRU9nWJyJO324=
github.com/ipfs/go-ipfs-files v0.1.1/go.mod h1:8xkIrMWH+Y5P7HvJ4Yc5XWwIW2e52dyXUiC0tZyjDbM=
github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
Expand All @@ -237,7 +234,6 @@ github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5W
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
Expand Down

0 comments on commit bae8333

Please sign in to comment.