mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed? - Remove workflow specific logic in migration activities - Add `SkipForceReload` flag to admin describeMutableState api to avoid unnecessary mutable state loading. ## Why? - Migration workflow needs to work with chasm runs as well, not just workflows. ## How did you test it? - [x] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package describemutablestate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.temporal.io/server/api/historyservice/v1"
|
|
"go.temporal.io/server/chasm"
|
|
"go.temporal.io/server/common/definition"
|
|
"go.temporal.io/server/common/locks"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/service/history/api"
|
|
historyi "go.temporal.io/server/service/history/interfaces"
|
|
"go.temporal.io/server/service/history/workflow"
|
|
)
|
|
|
|
func Invoke(
|
|
ctx context.Context,
|
|
req *historyservice.DescribeMutableStateRequest,
|
|
shardContext historyi.ShardContext,
|
|
workflowConsistencyChecker api.WorkflowConsistencyChecker,
|
|
) (_ *historyservice.DescribeMutableStateResponse, retError error) {
|
|
namespaceID := namespace.ID(req.GetNamespaceId())
|
|
err := api.ValidateNamespaceUUID(namespaceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
chasmLease, err := workflowConsistencyChecker.GetChasmLease(
|
|
ctx,
|
|
nil,
|
|
definition.NewWorkflowKey(
|
|
req.NamespaceId,
|
|
req.Execution.WorkflowId,
|
|
req.Execution.RunId,
|
|
),
|
|
chasm.ArchetypeAny, // DescribeMutableState works for all Archetypes.
|
|
locks.PriorityHigh,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { chasmLease.GetReleaseFn()(retError) }()
|
|
|
|
response := &historyservice.DescribeMutableStateResponse{}
|
|
if chasmLease.GetContext().(*workflow.ContextImpl).MutableState != nil {
|
|
msb := chasmLease.GetContext().(*workflow.ContextImpl).MutableState
|
|
response.CacheMutableState = msb.CloneToProto()
|
|
}
|
|
|
|
if !req.GetSkipForceReload() {
|
|
// Clear mutable state to force reload from persistence.
|
|
chasmLease.GetContext().Clear()
|
|
}
|
|
|
|
mutableState, err := chasmLease.GetContext().LoadMutableState(ctx, shardContext)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response.DatabaseMutableState = mutableState.CloneToProto()
|
|
return response, nil
|
|
}
|