mirror of
https://github.com/rocky-linux/peridot.git
synced 2024-11-18 03:11:24 +00:00
Make Temporal namespace configurable
This commit is contained in:
parent
80a9f32441
commit
3245c6099c
@ -9,6 +9,7 @@ go_library(
|
||||
"//vendor/github.com/sirupsen/logrus",
|
||||
"//vendor/github.com/spf13/pflag",
|
||||
"//vendor/github.com/spf13/viper",
|
||||
"//vendor/go.temporal.io/api/workflowservice/v1:workflowservice",
|
||||
"//vendor/go.temporal.io/sdk/client",
|
||||
"@org_golang_google_grpc//:go_default_library",
|
||||
"@org_golang_google_grpc//credentials",
|
||||
|
@ -31,14 +31,18 @@
|
||||
package temporalutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
"go.temporal.io/api/workflowservice/v1"
|
||||
"go.temporal.io/sdk/client"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AddFlags(pflags *pflag.FlagSet) {
|
||||
@ -66,5 +70,31 @@ func NewClient(opts client.Options) (client.Client, error) {
|
||||
|
||||
opts.HostPort = temporalHostPort
|
||||
|
||||
bycNs := os.Getenv("BYC_NS")
|
||||
temporalNamespace := os.Getenv("TEMPORAL_NAMESPACE")
|
||||
if temporalNamespace != "" {
|
||||
bycNs = temporalNamespace
|
||||
}
|
||||
if opts.Namespace != "" {
|
||||
bycNs = opts.Namespace
|
||||
}
|
||||
if bycNs == "" {
|
||||
bycNs = "default"
|
||||
}
|
||||
|
||||
nscl, err := client.NewNamespaceClient(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dur := 5 * 24 * time.Hour
|
||||
err = nscl.Register(context.TODO(), &workflowservice.RegisterNamespaceRequest{
|
||||
Namespace: bycNs,
|
||||
WorkflowExecutionRetentionPeriod: &dur,
|
||||
})
|
||||
if err != nil && !strings.Contains(err.Error(), "Namespace already exists") {
|
||||
return nil, err
|
||||
}
|
||||
opts.Namespace = bycNs
|
||||
|
||||
return client.NewClient(opts)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user