In the Go SDK, a client must be created before the worker can be created. This has the perhaps unintended side effect of forcing the client and worker to be created in the same function in order to defer closing the client. Is there any logical reason why the step of creating the worker, and then setting its client couldn’t be teased apart? Another way to ask the question is, does a Worker actually use the Client between being created and being run? Here’s something like what I’d like to be able to do:
var w worker.Worker
func initApp(config map[string]interface{}) (err error) {
w, err = worker.New(nil, "queuename", worker.Options{})
...
w.RegisterWorkflow(...)
w.RegisterActivity(...)
w.RegisterActivity(...)
return err
}
func startServer() (err error) {
c, err := client.NewClient(client.Options{
HostPort: client.DefaultHostPort,
})
...
defer c.Close()
w.SetClient(c)
err = w.Run(worker.InterruptCh())
...
return err
}