mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-12-22 02:47:32 +01:00
fix: (redis) parse redis dsn
This commit is contained in:
parent
6902033586
commit
b4a7668ca4
17
cmd/init.go
17
cmd/init.go
@ -47,18 +47,23 @@ func loadConfig(configFilePath string, k *koanf.Koanf) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func connectDbs(dsn string) error {
|
||||
func connectDb(dsn string) error {
|
||||
var err error
|
||||
db, err = pgxpool.Connect(context.Background(), dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rClient = asynq.RedisClientOpt{
|
||||
Addr: conf.Db.Redis,
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseRedis(dsn string) (asynq.RedisConnOpt, error) {
|
||||
rconn, err := asynq.ParseRedisURI(dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return rconn, nil
|
||||
}
|
||||
|
||||
func connectCicNet(rpcProvider string, tokenIndex common.Address) error {
|
||||
@ -82,7 +87,7 @@ func loadQueries(sqlFile string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func bootstrapScheduler(redis asynq.RedisClientOpt) (*asynq.Scheduler, error) {
|
||||
func bootstrapScheduler(redis asynq.RedisConnOpt) (*asynq.Scheduler, error) {
|
||||
scheduler := asynq.NewScheduler(redis, nil)
|
||||
|
||||
for k, v := range conf.Syncers {
|
||||
@ -99,7 +104,7 @@ func bootstrapScheduler(redis asynq.RedisClientOpt) (*asynq.Scheduler, error) {
|
||||
return scheduler, nil
|
||||
}
|
||||
|
||||
func bootstrapProcessor(redis asynq.RedisClientOpt) (*asynq.Server, *asynq.ServeMux) {
|
||||
func bootstrapProcessor(redis asynq.RedisConnOpt) (*asynq.Server, *asynq.ServeMux) {
|
||||
processorServer := asynq.NewServer(
|
||||
redis,
|
||||
asynq.Config{
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"cic-dw/pkg/cicnet"
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/knadh/koanf"
|
||||
"github.com/lmittmann/w3"
|
||||
@ -17,7 +16,6 @@ import (
|
||||
var (
|
||||
k = koanf.New(".")
|
||||
|
||||
rClient asynq.RedisClientOpt
|
||||
queries goyesql.Queries
|
||||
conf config
|
||||
db *pgxpool.Pool
|
||||
@ -35,7 +33,7 @@ func init() {
|
||||
log.Fatal().Err(err).Msg("failed to load sql file")
|
||||
}
|
||||
|
||||
if err := connectDbs(conf.Db.Postgres); err != nil {
|
||||
if err := connectDb(conf.Db.Postgres); err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to connect to postgres")
|
||||
}
|
||||
|
||||
@ -46,6 +44,11 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
rClient, err := parseRedis(conf.Db.Redis)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not parse redis connection string")
|
||||
}
|
||||
|
||||
scheduler, err := bootstrapScheduler(rClient)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not bootstrap scheduler")
|
||||
|
@ -1,6 +1,6 @@
|
||||
[db]
|
||||
postgres = "postgresql://postgres:postgres@127.0.0.1:5432/cic_dw"
|
||||
redis = "127.0.0.1:6379"
|
||||
redis = "redis://127.0.0.1:6379/0"
|
||||
|
||||
[chain]
|
||||
index = "0x5A1EB529438D8b3cA943A45a48744f4c73d1f098"
|
||||
@ -8,5 +8,5 @@ rpc = "http://127.0.0.1:8545"
|
||||
|
||||
[syncers]
|
||||
cache = "@every 20s"
|
||||
ussd = "@every 30"
|
||||
ussd = "@every 30s"
|
||||
token = "@every 1m"
|
Loading…
Reference in New Issue
Block a user