verifa / horizon

Building blocks and patterns for creating a minimal internal developer platform
Apache License 2.0
10 stars 2 forks source link

NATS Startup errors. #18

Closed gedw99 closed 3 months ago

gedw99 commented 4 months ago

Hey @jlarfors

Just had some more time to spend on this.

Getting stuck with NATS startup. Its trying to startup an embedded NATS Jetstream Server by default ?

I was wanting to point it to a NATS Cluster to try out some things.

I am latest main version btw...


horizon % go run ./cmd/ci/ci.go -generate
πŸ“ generating files
2024/06/29 13:41:43 INFO exec cmd="/opt/homebrew/opt/go/libexec/bin/go run -mod=readonly github.com/a-h/templ/cmd/templ generate"
Processing path: /Users/apple/workspace/go/src/github.com/gedw99/horizon
Generating production code: /Users/apple/workspace/go/src/github.com/gedw99/horizon
(βœ“) Generated code for "/Users/apple/workspace/go/src/github.com/gedw99/horizon/pkg/hzctl/login/login.templ" in 3.007208ms
(βœ“) Generated code for "/Users/apple/workspace/go/src/github.com/gedw99/horizon/examples/greetings/portal.templ" in 6.532625ms
(βœ“) Generated code for "/Users/apple/workspace/go/src/github.com/gedw99/horizon/pkg/gateway/icons.templ" in 4.710875ms
(βœ“) Generated code for "/Users/apple/workspace/go/src/github.com/gedw99/horizon/pkg/gateway/gateway.templ" in 5.247709ms
(βœ“) Generated code for "/Users/apple/workspace/go/src/github.com/gedw99/horizon/pkg/gateway/accounts.templ" in 7.058834ms
(βœ“) Generated code for 5 templates with 0 errors in 9.832166ms
2024/06/29 13:41:44 INFO done cmd="/opt/homebrew/opt/go/libexec/bin/go run -mod=readonly github.com/a-h/templ/cmd/templ generate"
βœ… content generated

apple@192 horizon % go run ./cmd/horizon/horizon.go
NATS DIR:  /var/folders/pj/n3sth0z55md7lydld97r8mmh0000gn/T/horizon
horizon.go:15: ERROR horizon server failed error="starting server: starting nats server: server not ready after 4s"
exit status 1

# Wish there was more info for Help :)
go run ./cmd/horizon/horizon.go -h 
jlarfors commented 4 months ago

@gedw99 currently the only way it is running is using an embedded NATS server with Jetstream enabled.

You can look at the code for the horizon main function, it is not very long and does no flag parsing :)

https://github.com/verifa/horizon/blob/main/cmd/horizon/horizon.go

If you want to try using an existing NATS server you could write your own main function and use the WithNATSConn() option in server: https://github.com/verifa/horizon/blob/main/pkg/server/server.go#L39

I didn't feel like writing a complex CLI with lots of argument/config handling at this time when it is arguably easier for people to write their own main function for their specific needs.

gedw99 commented 4 months ago

Thanks but the embedded nats server is failing. Could you have a look ?

I would then be able to extend it to work with a nats cluster as a PR

jlarfors commented 3 months ago

Sorry for the late reply, I just came back from holidays. I tested with a fresh clone of the repository and it works for me. Which OS are you running on? Could you try extending the timeout to see if that works (it is currently hardcoded)?

https://github.com/verifa/horizon/blob/main/pkg/natsutil/server.go#L155

gedw99 commented 3 months ago

I did a git pull and make and it works now.

not sure why :)

I wil close, but feel free to open if you need to.

Hope you had a good holiday :)