Make Temporal namespace configurable

This commit is contained in:
Mustafa Gezen 2022-07-16 01:07:15 +02:00
parent 80a9f32441
commit 3245c6099c
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1
2 changed files with 31 additions and 0 deletions

View File

@ -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",

View File

@ -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)
}