This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
options.go
155 lines (135 loc) · 4.89 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
package temporalite
import (
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/temporal"
"github.com/temporalio/temporalite/internal/liteconfig"
)
// WithLogger overrides the default logger.
func WithLogger(logger log.Logger) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.Logger = logger
})
}
// WithDatabaseFilePath persists state to the file at the specified path.
func WithDatabaseFilePath(filepath string) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.Ephemeral = false
cfg.DatabaseFilePath = filepath
})
}
// WithPersistenceDisabled disables file persistence and uses the in-memory storage driver.
// State will be reset on each process restart.
func WithPersistenceDisabled() ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.Ephemeral = true
})
}
// WithUI enables the Temporal web interface.
//
// When unspecified, Temporal will run in headless mode.
//
// This option accepts a UIServer implementation in order to avoid bloating
// programs that do not need to embed the UI.
// See ./cmd/temporalite/main.go for an example of usage.
func WithUI(server liteconfig.UIServer) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.UIServer = server
})
}
// WithFrontendPort sets the listening port for the temporal-frontend GRPC service.
//
// When unspecified, the default port number of 7233 is used.
func WithFrontendPort(port int) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.FrontendPort = port
})
}
// WithMetricsPort sets the listening port for metrics.
//
// When unspecified, the port will be system-chosen.
func WithMetricsPort(port int) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.MetricsPort = port
})
}
// WithFrontendIP binds the temporal-frontend GRPC service to a specific IP (eg. `0.0.0.0`)
// Check net.ParseIP for supported syntax; only IPv4 is supported.
//
// When unspecified, the frontend service will bind to localhost.
func WithFrontendIP(address string) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.FrontendIP = address
})
}
// WithDynamicPorts starts Temporal on system-chosen ports.
func WithDynamicPorts() ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.DynamicPorts = true
})
}
// WithNamespaces registers each namespace on Temporal start.
func WithNamespaces(namespaces ...string) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.Namespaces = append(cfg.Namespaces, namespaces...)
})
}
// WithSQLitePragmas applies pragma statements to SQLite on Temporal start.
func WithSQLitePragmas(pragmas map[string]string) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
if cfg.SQLitePragmas == nil {
cfg.SQLitePragmas = make(map[string]string)
}
for k, v := range pragmas {
cfg.SQLitePragmas[k] = v
}
})
}
// WithUpstreamOptions registers Temporal server options.
func WithUpstreamOptions(options ...temporal.ServerOption) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.UpstreamOptions = append(cfg.UpstreamOptions, options...)
})
}
// WithBaseConfig sets the default Temporal server configuration.
//
// Storage and client configuration will always be overridden, however base config can be
// used to enable settings like TLS or authentication.
func WithBaseConfig(base *config.Config) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
cfg.BaseConfig = base
})
}
// WithDynamicConfigValue sets the given dynamic config key with the given set
// of values. This will overwrite the key if already set.
func WithDynamicConfigValue(key dynamicconfig.Key, value []dynamicconfig.ConstrainedValue) ServerOption {
return newApplyFuncContainer(func(cfg *liteconfig.Config) {
if cfg.DynamicConfig == nil {
cfg.DynamicConfig = dynamicconfig.StaticClient{}
}
cfg.DynamicConfig[key] = value
})
}
// WithSearchAttributeCacheDisabled disables search attribute caching. This
// delegates to WithDynamicConfigValue.
func WithSearchAttributeCacheDisabled() ServerOption {
return WithDynamicConfigValue(
dynamicconfig.ForceSearchAttributesCacheRefreshOnRead,
[]dynamicconfig.ConstrainedValue{{Value: true}},
)
}
type applyFuncContainer struct {
applyInternal func(*liteconfig.Config)
}
func (fso *applyFuncContainer) apply(cfg *liteconfig.Config) {
fso.applyInternal(cfg)
}
func newApplyFuncContainer(apply func(*liteconfig.Config)) *applyFuncContainer {
return &applyFuncContainer{
applyInternal: apply,
}
}