Files
tasks/service/history/api/unpauseworkflow/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

105 lines
3.2 KiB
Go

package unpauseworkflow
import (
"context"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"github.com/hanzoai/tasks/api/historyservice/v1"
"github.com/hanzoai/tasks/common/definition"
"github.com/hanzoai/tasks/common/namespace"
"github.com/hanzoai/tasks/service/history/api"
"github.com/hanzoai/tasks/service/history/consts"
historyi "github.com/hanzoai/tasks/service/history/interfaces"
)
func Invoke(
ctx context.Context,
req *historyservice.UnpauseWorkflowExecutionRequest,
shard historyi.ShardContext,
workflowConsistencyChecker api.WorkflowConsistencyChecker,
) (resp *historyservice.UnpauseWorkflowExecutionResponse, retError error) {
namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId()), req.GetUnpauseRequest().GetWorkflowId())
if err != nil {
return nil, err
}
namespaceID := namespaceEntry.ID()
unpauseRequest := req.GetUnpauseRequest()
if unpauseRequest == nil {
return nil, serviceerror.NewInvalidArgument("unpause request is nil.")
}
if err := validateUnpauseRequest(unpauseRequest, shard); err != nil {
return nil, err
}
err = api.GetAndUpdateWorkflowWithNew(
ctx,
nil,
definition.NewWorkflowKey(
namespaceID.String(),
unpauseRequest.GetWorkflowId(),
unpauseRequest.GetRunId(),
),
func(workflowLease api.WorkflowLease) (*api.UpdateWorkflowAction, error) {
mutableState := workflowLease.GetMutableState()
releaseFn := workflowLease.GetReleaseFn()
// Make sure the workflow is not closed.
if !mutableState.IsWorkflowExecutionRunning() {
// in-memory mutable state is still clean, release the lock with nil error to prevent
// clearing and reloading mutable state
releaseFn(nil)
return nil, consts.ErrWorkflowCompleted
}
// Ensure that the workflow is already paused
if mutableState.GetExecutionState().GetStatus() != enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED {
releaseFn(nil)
return nil, serviceerror.NewFailedPrecondition("workflow is not paused.")
}
// Add the workflow execution unpaused event
_, err := mutableState.AddWorkflowExecutionUnpausedEvent(
unpauseRequest.GetIdentity(),
unpauseRequest.GetReason(),
unpauseRequest.GetRequestId(),
)
if err != nil {
return nil, err
}
return &api.UpdateWorkflowAction{
Noop: false,
CreateWorkflowTask: true, // Create workflow task when unpausing
}, nil
},
nil,
shard,
workflowConsistencyChecker,
)
if err != nil {
return nil, err
}
// Return response
return &historyservice.UnpauseWorkflowExecutionResponse{}, nil
}
func validateUnpauseRequest(req *workflowservice.UnpauseWorkflowExecutionRequest, shard historyi.ShardContext) error {
// verify size limits of reason, request id and identity.
if len(req.GetReason()) > shard.GetConfig().MaxIDLengthLimit() {
return serviceerror.NewInvalidArgument("reason is too long.")
}
if len(req.GetRequestId()) > shard.GetConfig().MaxIDLengthLimit() {
return serviceerror.NewInvalidArgument("request id is too long.")
}
if len(req.GetIdentity()) > shard.GetConfig().MaxIDLengthLimit() {
return serviceerror.NewInvalidArgument("identity is too long.")
}
return nil
}