Files
tasks/temporal/server_options.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

133 lines
3.5 KiB
Go

package temporal
import (
"errors"
"fmt"
"net/http"
"slices"
"github.com/hanzoai/tasks/client"
"github.com/hanzoai/tasks/common/authorization"
"github.com/hanzoai/tasks/common/config"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/membership/static"
"github.com/hanzoai/tasks/common/metrics"
persistenceClient "github.com/hanzoai/tasks/common/persistence/client"
"github.com/hanzoai/tasks/common/persistence/visibility"
"github.com/hanzoai/tasks/common/primitives"
"github.com/hanzoai/tasks/common/resolver"
"github.com/hanzoai/tasks/common/rpc/encryption"
"github.com/hanzoai/tasks/common/searchattribute"
"google.golang.org/grpc"
)
type (
synchronizationModeParams struct {
blockingStart bool
interruptCh <-chan any
}
serverOptions struct {
serviceNames map[primitives.ServiceName]struct{}
config *config.Config
configDir string
env string
zone string
configFilePath string
hostsByService map[primitives.ServiceName]static.Hosts
startupSynchronizationMode synchronizationModeParams
logger log.Logger
namespaceLogger log.Logger
authorizer authorization.Authorizer
tlsConfigProvider encryption.TLSConfigProvider
claimMapper authorization.ClaimMapper
audienceGetter authorization.JWTAudienceMapper
persistenceServiceResolver resolver.ServiceResolver
elasticsearchHttpClient *http.Client
dynamicConfigClient dynamicconfig.Client
customDataStoreFactory persistenceClient.AbstractDataStoreFactory
customVisibilityStoreFactory visibility.VisibilityStoreFactory
clientFactoryProvider client.FactoryProvider
searchAttributesMapper searchattribute.Mapper
customFrontendInterceptors []grpc.UnaryServerInterceptor
metricHandler metrics.Handler
}
)
func newServerOptions(opts []ServerOption) *serverOptions {
so := &serverOptions{
// Set defaults here.
persistenceServiceResolver: resolver.NewNoopResolver(),
}
for _, opt := range opts {
opt.apply(so)
}
return so
}
func (so *serverOptions) loadAndValidate() error {
for serviceName := range so.serviceNames {
if !slices.Contains(Services, string(serviceName)) {
return fmt.Errorf("invalid service %q in service list %v", serviceName, so.serviceNames)
}
}
if so.config == nil {
err := so.loadConfig()
if err != nil {
return fmt.Errorf("unable to load config: %w", err)
}
}
err := so.validateConfig()
if err != nil {
return fmt.Errorf("config validation error: %w", err)
}
return nil
}
func (so *serverOptions) loadConfig() error {
if so.configFilePath != "" {
if so.env != "" || so.configDir != "" || so.zone != "" {
return errors.New("env, config, zone can not be set if configFilePath is set")
}
cfg, err := config.Load(
config.WithConfigFile(so.configFilePath),
)
if err != nil {
return fmt.Errorf("could not load config file: %w", err)
}
so.config = cfg
return nil
}
cfg, err := config.Load(
config.WithEnv(so.env),
config.WithConfigDir(so.configDir),
config.WithZone(so.zone),
)
if err != nil {
return fmt.Errorf("could not load config file: %w", err)
}
so.config = cfg
return nil
}
func (so *serverOptions) validateConfig() error {
if err := so.config.Validate(); err != nil {
return err
}
for name := range so.serviceNames {
if _, ok := so.config.Services[string(name)]; !ok {
return fmt.Errorf("%q service is missing in config", name)
}
}
return nil
}