Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/hasura config #23

Merged
merged 15 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/metadata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ COPY ./cmd/metadata/mappings ./mappings
COPY ./cmd/metadata/graphql ./graphql
COPY ./build/*.yml ./
COPY ./cmd/metadata/views/*.sql ./views/
COPY ./cmd/metadata/custom_hasura_config ./custom_hasura_config

ENTRYPOINT ["/go/bin/dipdup-metadata"]
3 changes: 3 additions & 0 deletions cmd/metadata/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (c *Config) Substitute() error {
return err
}
}
if c.Config.Hasura != nil {
c.Config.Hasura.SetSourceName()
}
return nil
}

Expand Down
Empty file.
14 changes: 10 additions & 4 deletions cmd/metadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ func main() {
log.Err(err).Msg("createViews")
return
}

custom_configs, err := hasura.ReadCustomConfigs(ctx, cfg.Database, "custom_hasura_config")
if err != nil {
log.Err(err).Msg("readCustomHasuraConfigs")
return
}

var indexers sync.Map
var indexerCancels sync.Map

var hasuraInit sync.Once
for network, indexer := range cfg.Metadata.Indexers {
go func(network string, ind *config.Indexer) {
result, err := startIndexer(ctx, cfg, *ind, network, prometheusService, views, &hasuraInit)
result, err := startIndexer(ctx, cfg, *ind, network, prometheusService, views, custom_configs, &hasuraInit)
if err != nil {
log.Err(err).Msg("")
} else {
Expand All @@ -91,7 +97,7 @@ func main() {
case <-ctx.Done():
return
case <-ticker.C:
result, err := startIndexer(ctx, cfg, *ind, network, prometheusService, views, &hasuraInit)
result, err := startIndexer(ctx, cfg, *ind, network, prometheusService, views, custom_configs, &hasuraInit)
if err != nil {
log.Err(err).Msg("")
} else {
Expand Down Expand Up @@ -144,7 +150,7 @@ func initPrometheus(cfg *golibConfig.Prometheus) *prometheus.Service {
return prometheusService
}

func startIndexer(ctx context.Context, cfg config.Config, indexerConfig config.Indexer, network string, prom *prometheus.Service, views []string, hasuraInit *sync.Once) (startResult, error) {
func startIndexer(ctx context.Context, cfg config.Config, indexerConfig config.Indexer, network string, prom *prometheus.Service, views []string, customConfigs []hasura.Request, hasuraInit *sync.Once) (startResult, error) {
var result startResult
indexerCtx, cancel := context.WithCancel(ctx)

Expand All @@ -165,7 +171,7 @@ func startIndexer(ctx context.Context, cfg config.Config, indexerConfig config.I
Config: cfg.Hasura,
DatabaseConfig: cfg.Database,
Views: views,
CustomConfigurations: nil,
CustomConfigurations: customConfigs,
Models: []any{new(models.TokenMetadata), new(models.ContractMetadata)},
}); err != nil {
log.Err(err).Msg("hasura.Create")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/aws/aws-sdk-go v1.43.31
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/dipdup-net/go-lib v0.2.10
github.com/dipdup-net/go-lib v0.2.13
github.com/disintegration/imaging v1.6.2
github.com/elastic/go-elasticsearch/v8 v8.1.0
github.com/go-pg/pg/v10 v10.10.6
Expand Down Expand Up @@ -96,7 +96,7 @@ require (
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gorm.io/driver/mysql v1.3.3 // indirect
gorm.io/driver/postgres v1.3.3 // indirect
gorm.io/driver/sqlite v1.3.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ 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.2.10 h1:MJPijh0I/xWB8dbQVb0+He0k7ODAOv9c6axT94wv/LE=
github.com/dipdup-net/go-lib v0.2.10/go.mod h1:RjVhNv63RE3pOAeHLwnspa2UjJi80k/Kelwv7aN1ETE=
github.com/dipdup-net/go-lib v0.2.13 h1:8SUR3n8LOqoKyl9rPluzzvU0XjeME0eHnzzDlw3WAME=
github.com/dipdup-net/go-lib v0.2.13/go.mod h1:RCYx6FV8+7qQkC1dCP8zn8WTlsFRXXx/D4N+2mw1GJg=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/ebellocchia/go-base58 v0.1.0 h1:0w/ODEfZnOPW5KW0QY/Xpb1fxba/BxQJMUa5iYzpljk=
Expand Down Expand Up @@ -848,6 +848,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.3.3 h1:jXG9ANrwBc4+bMvBcSl8zCfPBaVoPyBEBshA8dA93X8=
gorm.io/driver/mysql v1.3.3/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U=
gorm.io/driver/postgres v1.3.3 h1:y6DU2kJgDNisxfAlmxRaQZOIy4ytnuYrpzpSFYnSfCY=
Expand Down