Skip to content

Commit

Permalink
fixup! feat: add node-startup-prep-util
Browse files Browse the repository at this point in the history
  • Loading branch information
endersonmaia committed May 29, 2024
1 parent 1499cb3 commit 8b5ebba
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 12 additions & 9 deletions utils/node-startup-prep/main.go → utils/node-pre-start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@ func main() {
if !exists {
log.Fatalln("ERR: Missing environment variable CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT")
}
log.Printf("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT=%s service=node-startup-prep", _redisEndpoint)
u, err := url.Parse(_redisEndpoint)
redisEndpoint, err := url.Parse(_redisEndpoint)
if err != nil {
log.Fatalln("ERR: ", err)
}
var redisEndpoint = fmt.Sprintf("%s:%s", u.Hostname(), u.Port())
log.Printf("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT=%s://%s service=node-startup-prep", redisEndpoint.Scheme, redisEndpoint.Host)

postgresEndpoint, exists := os.LookupEnv("CARTESI_POSTGRES_ENDPOINT")
_postgresEndpoint, exists := os.LookupEnv("CARTESI_POSTGRES_ENDPOINT")
if !exists {
log.Fatalln("ERR: Missing environment variable CARTESI_POSTGRES_ENDPOINT service=node-startup-prep")
}
log.Printf("CARTESI_POSTGRES_ENDPOINT=%s service=node-startup-prep", postgresEndpoint)
postgresEndpoint, err := url.Parse(_postgresEndpoint)
if err != nil {
log.Fatalln("ERR: ", err)
}
log.Printf("CARTESI_POSTGRES_ENDPOINT=%s://%s:[REDACTED]@%s/ service=node-startup-prep", postgresEndpoint.Scheme, postgresEndpoint.User.Username(), postgresEndpoint.Host)

// Clean inputs and outputs streams
rdb := redis.NewClient(&redis.Options{
Addr: redisEndpoint,
Password: "", // no password set
DB: 0, // use default DB
Addr: redisEndpoint.Host,
Password: redisEndpoint.User.String(),
DB: 0, // use default DB
})

_, err = rdb.Ping(ctx).Result()
Expand All @@ -74,7 +77,7 @@ func main() {
log.Println("REDIS: Cleaned inputs and outputs streams.")

//connect to a PostgreSQL database
db, err := sqlx.Connect("postgres", postgresEndpoint)
db, err := sqlx.Connect("postgres", postgresEndpoint.String())
if err != nil {
log.Fatalln(err)
}
Expand Down

0 comments on commit 8b5ebba

Please sign in to comment.