Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Add WithUpstreamOptions server option #10

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/temporalite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/urfave/cli/v2"
"go.temporal.io/server/common/headers"
"go.temporal.io/server/common/log"
"go.temporal.io/server/temporal"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -106,6 +107,9 @@ func buildCLI() *cli.App {
temporalite.WithFrontendPort(c.Int(portFlag)),
temporalite.WithDatabaseFilePath(c.String(dbPathFlag)),
temporalite.WithNamespaces(c.StringSlice(namespaceFlag)...),
temporalite.WithUpstreamOptions(
temporal.InterruptOn(temporal.InterruptCh()),
),
}
if c.Bool(ephemeralFlag) {
opts = append(opts, temporalite.WithPersistenceDisabled())
Expand Down
2 changes: 2 additions & 0 deletions internal/liteconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite"
"go.temporal.io/server/temporal"
)

const (
Expand All @@ -30,6 +31,7 @@ type Config struct {
DynamicPorts bool
Namespaces []string
Logger log.Logger
UpstreamOptions []temporal.ServerOption
portProvider *portProvider
}

Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package temporalite

import (
"go.temporal.io/server/common/log"
"go.temporal.io/server/temporal"

"github.com/DataDog/temporalite/internal/liteconfig"
)
Expand Down Expand Up @@ -54,6 +55,13 @@ func WithNamespaces(namespaces ...string) ServerOption {
})
}

// WithUpstreamOptions registers Temporal server options.
func WithUpstreamOptions(options ...temporal.ServerOption) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.UpstreamOptions = append(cfg.UpstreamOptions, options...)
})
}

type applyFuncContainer struct {
applyInternal func(*liteconfig.Config)
}
Expand Down
27 changes: 16 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,23 @@ func NewServer(opts ...ServerOption) (*Server, error) {
return nil, fmt.Errorf("unable to instantiate claim mapper: %w", err)
}

serverOpts := []temporal.ServerOption{
temporal.WithConfig(cfg),
temporal.ForServices(temporal.Services),
temporal.WithLogger(c.Logger),
temporal.WithAuthorizer(authorizer),
temporal.WithClaimMapper(func(cfg *config.Config) authorization.ClaimMapper {
return claimMapper
}),
temporal.WithDynamicConfigClient(dynamicconfig.NewNoopClient()),
}

if len(c.UpstreamOptions) > 0 {
serverOpts = append(serverOpts, c.UpstreamOptions...)
}

s := &Server{
internal: temporal.NewServer(
temporal.WithConfig(cfg),
temporal.ForServices(temporal.Services),
temporal.WithLogger(c.Logger),
temporal.InterruptOn(temporal.InterruptCh()),
sevein marked this conversation as resolved.
Show resolved Hide resolved
temporal.WithAuthorizer(authorizer),
temporal.WithClaimMapper(func(cfg *config.Config) authorization.ClaimMapper {
return claimMapper
}),
temporal.WithDynamicConfigClient(dynamicconfig.NewNoopClient()),
),
internal: temporal.NewServer(serverOpts...),
frontendHostPort: cfg.PublicClient.HostPort,
config: c,
}
Expand Down