diff --git a/temporalutils/BUILD.bazel b/temporalutils/BUILD.bazel index 69bb03e..6ddfb50 100644 --- a/temporalutils/BUILD.bazel +++ b/temporalutils/BUILD.bazel @@ -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", diff --git a/temporalutils/client.go b/temporalutils/client.go index 003fddd..157d29c 100644 --- a/temporalutils/client.go +++ b/temporalutils/client.go @@ -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) }