mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - The `ChasmRequestInterceptor` has been split in two! `ChasmRequestEngineInterceptor` does everything except inject `chasm.VisibilityManager`, which is done by `ChasmRequestVisibilityInterceptor`. - Note that the test doesn't include a matching `hasVisibilityCtx` assert to `hasEngineCtx` because I think making that getter public would make the public API earnestly more confusing for consumers ## Why? - Frontend needs visibilityMgr injected so that it can handle FE->Vis queries without hopping through history. The previous interceptor assumed `chasm.Engine` was always available, which it isn't, for history. I'd also workshopped making engine an optional fx parameter, but eh. ## How did you test it? - Validated with scheduler functional tests, which use `chasm.ListExecutions` directly in frontend's `WorkflowHandler`.
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package visibility
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
"go.temporal.io/api/serviceerror"
|
|
"go.temporal.io/server/chasm"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
)
|
|
|
|
type ChasmVisibilityManager struct {
|
|
registry *chasm.Registry
|
|
visibilityMgr manager.VisibilityManager
|
|
}
|
|
|
|
var _ chasm.VisibilityManager = (*ChasmVisibilityManager)(nil)
|
|
|
|
func NewChasmVisibilityManager(
|
|
registry *chasm.Registry,
|
|
visibilityMgr manager.VisibilityManager,
|
|
) *ChasmVisibilityManager {
|
|
return &ChasmVisibilityManager{
|
|
registry: registry,
|
|
visibilityMgr: visibilityMgr,
|
|
}
|
|
}
|
|
|
|
func ChasmVisibilityManagerProvider(
|
|
registry *chasm.Registry,
|
|
visibilityMgr manager.VisibilityManager,
|
|
) chasm.VisibilityManager {
|
|
return NewChasmVisibilityManager(registry, visibilityMgr)
|
|
}
|
|
|
|
// ListExecutions implements the Engine interface for visibility queries.
|
|
func (e *ChasmVisibilityManager) ListExecutions(
|
|
ctx context.Context,
|
|
archetypeType reflect.Type,
|
|
request *chasm.ListExecutionsRequest,
|
|
) (*chasm.ListExecutionsResponse[*commonpb.Payload], error) {
|
|
archetypeID, ok := e.registry.ArchetypeIDOf(archetypeType)
|
|
if !ok {
|
|
return nil, serviceerror.NewInternal("unknown chasm component type: " + archetypeType.String())
|
|
}
|
|
|
|
visReq := &manager.ListChasmExecutionsRequest{
|
|
ArchetypeID: archetypeID,
|
|
NamespaceID: namespace.ID(request.NamespaceID),
|
|
Namespace: namespace.Name(request.NamespaceName),
|
|
PageSize: request.PageSize,
|
|
NextPageToken: request.NextPageToken,
|
|
Query: request.Query,
|
|
}
|
|
|
|
return e.visibilityMgr.ListChasmExecutions(ctx, visReq)
|
|
}
|
|
|
|
// CountExecutions implements the Engine interface for visibility queries.
|
|
func (e *ChasmVisibilityManager) CountExecutions(
|
|
ctx context.Context,
|
|
archetypeType reflect.Type,
|
|
request *chasm.CountExecutionsRequest,
|
|
) (*chasm.CountExecutionsResponse, error) {
|
|
archetypeID, ok := e.registry.ArchetypeIDOf(archetypeType)
|
|
if !ok {
|
|
return nil, serviceerror.NewInternal("unknown chasm component type: " + archetypeType.String())
|
|
}
|
|
|
|
visReq := &manager.CountChasmExecutionsRequest{
|
|
ArchetypeID: archetypeID,
|
|
NamespaceID: namespace.ID(request.NamespaceID),
|
|
Namespace: namespace.Name(request.NamespaceName),
|
|
Query: request.Query,
|
|
}
|
|
|
|
return e.visibilityMgr.CountChasmExecutions(ctx, visReq)
|
|
}
|