Files
tasks/service/history/api/deleteworkflow/api.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

100 lines
3.5 KiB
Go

package deleteworkflow
import (
"context"
commonpb "go.temporal.io/api/common/v1"
"github.com/hanzoai/tasks/api/historyservice/v1"
"github.com/hanzoai/tasks/common/definition"
"github.com/hanzoai/tasks/common/locks"
"github.com/hanzoai/tasks/common/namespace"
"github.com/hanzoai/tasks/service/history/api"
"github.com/hanzoai/tasks/service/history/consts"
"github.com/hanzoai/tasks/service/history/deletemanager"
historyi "github.com/hanzoai/tasks/service/history/interfaces"
"github.com/hanzoai/tasks/service/history/workflow"
)
func Invoke(
ctx context.Context,
request *historyservice.DeleteWorkflowExecutionRequest,
shardContext historyi.ShardContext,
workflowConsistencyChecker api.WorkflowConsistencyChecker,
workflowDeleteManager deletemanager.DeleteManager,
) (_ *historyservice.DeleteWorkflowExecutionResponse, retError error) {
workflowLease, err := workflowConsistencyChecker.GetWorkflowLease(
ctx,
nil,
definition.NewWorkflowKey(
request.NamespaceId,
request.WorkflowExecution.WorkflowId,
request.WorkflowExecution.RunId,
),
locks.PriorityLow,
)
if err != nil {
return nil, err
}
defer func() { workflowLease.GetReleaseFn()(retError) }()
// Open and Close workflow executions are deleted differently.
// Open workflow execution is deleted by terminating with special flag `deleteAfterTerminate` set to true.
// This flag will be carried over with CloseExecutionTask and workflow will be deleted as the last step while processing the task.
//
// Close workflow execution is deleted using DeleteExecutionTask.
//
// DeleteWorkflowExecution is not replicated automatically. Workflow executions must be deleted separately in each cluster.
// Although running workflows in active cluster are terminated first and the termination event might be replicated.
// In passive cluster, workflow executions are just deleted in regardless of its state.
if workflowLease.GetMutableState().IsWorkflowExecutionRunning() {
if request.GetClosedWorkflowOnly() {
// skip delete open workflow
return &historyservice.DeleteWorkflowExecutionResponse{}, nil
}
ns, err := shardContext.GetNamespaceRegistry().GetNamespaceByID(namespace.ID(request.GetNamespaceId()))
if err != nil {
return nil, err
}
if ns.ActiveInCluster(shardContext.GetClusterMetadata().GetCurrentClusterName()) {
// If workflow execution is running and in active cluster.
if err := api.UpdateWorkflowWithNew(
shardContext,
ctx,
workflowLease,
func(workflowLease api.WorkflowLease) (*api.UpdateWorkflowAction, error) {
mutableState := workflowLease.GetMutableState()
return api.UpdateWorkflowTerminate, workflow.TerminateWorkflow(
mutableState,
"Delete workflow execution",
nil,
consts.IdentityHistoryService,
true,
// TODO(bergundy): No links will be attached here for now, we may want to add support for this later though.
nil,
)
},
nil,
); err != nil {
return nil, err
}
return &historyservice.DeleteWorkflowExecutionResponse{}, nil
}
}
// If workflow execution is closed or in passive cluster.
if err := workflowDeleteManager.AddDeleteExecutionTask(
ctx,
namespace.ID(request.GetNamespaceId()),
&commonpb.WorkflowExecution{
WorkflowId: request.GetWorkflowExecution().GetWorkflowId(),
RunId: request.GetWorkflowExecution().GetRunId(),
},
workflowLease.GetMutableState(),
); err != nil {
return nil, err
}
return &historyservice.DeleteWorkflowExecutionResponse{}, nil
}