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

Commit

Permalink
Add WithUpstreamOptions server option (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein authored Oct 13, 2021
1 parent 94be8e0 commit 1cccf14
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
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()),
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

0 comments on commit 1cccf14

Please sign in to comment.