Skip to content

Commit

Permalink
Add token notifier to fetcher
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios committed Aug 14, 2024
1 parent 440180a commit 5a9c229
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions token/services/selector/sherdlock/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
driver3 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
driver2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokendb"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)
Expand Down Expand Up @@ -67,7 +69,7 @@ type fetcherProvider struct {

var fetchers = map[FetcherStrategy]fetchFunc{
Mixed: func(db *tokendb.DB, notifier *tokendb.Notifier, m *Metrics) tokenFetcher {
return newMixedFetcher(db, m)
return newMixedFetcher(db, notifier, m)
},
}

Expand Down Expand Up @@ -107,7 +109,12 @@ type mixedFetcher struct {
m *Metrics
}

func newMixedFetcher(tokenDB TokenDB, m *Metrics) *mixedFetcher {
func newMixedFetcher(tokenDB TokenDB, tokenNotifier driver2.TokenNotifier, m *Metrics) *mixedFetcher {
if err := tokenNotifier.Subscribe(func(operation driver3.Operation, m map[driver3.ColumnKey]string) {
logger.Warnf("New operation %v: [%v]", operation, m)
}); err != nil {
panic(err)
}
return &mixedFetcher{
lazyFetcher: NewLazyFetcher(tokenDB),
eagerFetcher: newCachedFetcher(tokenDB, freshnessInterval, maxQueries),
Expand Down
6 changes: 5 additions & 1 deletion token/services/selector/sherdlock/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@ func createManager(pgConnStr string, backoff time.Duration) (testutils.EnhancedM
if err != nil {
return nil, err
}
return testutils.NewEnhancedManager(NewManager(newMixedFetcher(tokenDB, newMetrics(&disabled.Provider{})), lockDB, testutils.TokenQuantityPrecision, backoff, 0), tokenDB), nil
tokenNotifier, err := postgres.NewTokenNotifier(db, opts)
if err != nil {
return nil, err
}
return testutils.NewEnhancedManager(NewManager(newMixedFetcher(tokenDB, tokenNotifier, newMetrics(&disabled.Provider{})), lockDB, testutils.TokenQuantityPrecision, backoff, 0), tokenDB), nil
}

0 comments on commit 5a9c229

Please sign in to comment.