mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package interceptor
|
|
|
|
import (
|
|
"go.temporal.io/api/serviceerror"
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"github.com/hanzoai/tasks/common/namespace"
|
|
)
|
|
|
|
// gRPC method request must implement either NamespaceNameGetter or NamespaceIDGetter
|
|
// for namespace specific metrics to be reported properly
|
|
type (
|
|
NamespaceNameGetter interface {
|
|
GetNamespace() string
|
|
}
|
|
|
|
NamespaceIDGetter interface {
|
|
GetNamespaceId() string
|
|
}
|
|
)
|
|
|
|
// MustGetNamespaceName returns request namespace name
|
|
// or EmptyName if there's error when retrieving namespace name,
|
|
// e.g. unable to find namespace
|
|
func MustGetNamespaceName(
|
|
namespaceRegistry namespace.Registry,
|
|
req any,
|
|
) namespace.Name {
|
|
namespaceName, err := GetNamespaceName(namespaceRegistry, req)
|
|
if err != nil {
|
|
return namespace.EmptyName
|
|
}
|
|
return namespaceName
|
|
}
|
|
|
|
func GetNamespaceName(
|
|
namespaceRegistry namespace.Registry,
|
|
req any,
|
|
) (namespace.Name, error) {
|
|
switch request := req.(type) {
|
|
case *workflowservice.RegisterNamespaceRequest:
|
|
// For namespace registration requests, we don't expect to find namespace so skip checking caches
|
|
// to avoid caching a NotFound error from persistence readthrough
|
|
return namespace.Name(request.GetNamespace()), nil
|
|
case NamespaceNameGetter:
|
|
namespaceName := namespace.Name(request.GetNamespace())
|
|
_, err := namespaceRegistry.GetNamespace(namespaceName)
|
|
if err != nil {
|
|
return namespace.EmptyName, err
|
|
}
|
|
return namespaceName, nil
|
|
|
|
case NamespaceIDGetter:
|
|
namespaceID := namespace.ID(request.GetNamespaceId())
|
|
namespaceName, err := namespaceRegistry.GetNamespaceName(namespaceID)
|
|
if err != nil {
|
|
return namespace.EmptyName, err
|
|
}
|
|
return namespaceName, nil
|
|
|
|
default:
|
|
return namespace.EmptyName, serviceerror.NewInternalf("unable to extract namespace info from request of type %T", req)
|
|
}
|
|
}
|