contribsys / faktory

Language-agnostic persistent background job server
https://contribsys.com/faktory/
Other
5.71k stars 228 forks source link

Wouldn't it be possible to configure the client using ways other than environment variables? #428

Closed soranoba closed 1 year ago

soranoba commented 1 year ago

Are you using an old version?: Yes Have you checked the changelogs to see if your issue has been fixed in a later version?

https://github.com/contribsys/faktory/blob/master/Changes.md https://github.com/contribsys/faktory/blob/master/Pro-Changes.md https://github.com/contribsys/faktory/blob/master/Ent-Changes.md


    pool, err := faktory.NewPool(5)
    if err != nil {
        panic(err)
    }

https://github.com/contribsys/faktory_worker_go/blob/3e08c6d43cd944ac5398c7b01219125e112ac7d0/test/main.go#L91-L94

Faktory is able to create pools. However, it can't load server config from anything other than environment variables when using pool, because pool package is internal.

I would like to write code like the following, which allows for more flexible configuration methods.

server := &client.Server{/* my settings here */}
pool, err := client.NewPoolWithFactory(5, func() (pool.Closeable, error) { return server.Open() })

Is this acceptable? Thanks.

mperham commented 1 year ago

What settings do you want to configure with Go? The server location changes for every user of the library; it should not be something which you hardcode into your Go code.

soranoba commented 1 year ago

Yes, but this issue is the client (worker) side of the story.

I want to read the Faktory server host and port from yaml on the client (worker) side with faktory_worker_go. In this yaml, other required DB hosts are described together.

mperham commented 1 year ago

Use os.Setenv("FAKTORY_URL", ...) and then call Open.

https://pkg.go.dev/os#Setenv

soranoba commented 1 year ago

Ah, I understand. Thanks.