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

83 lines
2.4 KiB
Go

package pauseactivity
import (
"context"
"go.temporal.io/api/workflowservice/v1"
"github.com/hanzoai/tasks/api/historyservice/v1"
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
"github.com/hanzoai/tasks/common/definition"
"github.com/hanzoai/tasks/service/history/api"
"github.com/hanzoai/tasks/service/history/consts"
historyi "github.com/hanzoai/tasks/service/history/interfaces"
"github.com/hanzoai/tasks/service/history/workflow"
"google.golang.org/protobuf/types/known/timestamppb"
)
func Invoke(
ctx context.Context,
request *historyservice.PauseActivityRequest,
shardContext historyi.ShardContext,
workflowConsistencyChecker api.WorkflowConsistencyChecker,
) (resp *historyservice.PauseActivityResponse, retError error) {
err := api.GetAndUpdateWorkflowWithNew(
ctx,
nil,
definition.NewWorkflowKey(
request.NamespaceId,
request.GetFrontendRequest().GetExecution().GetWorkflowId(),
request.GetFrontendRequest().GetExecution().GetRunId(),
),
func(workflowLease api.WorkflowLease) (*api.UpdateWorkflowAction, error) {
mutableState := workflowLease.GetMutableState()
frontendRequest := request.GetFrontendRequest()
var activityIDs []string
switch a := frontendRequest.GetActivity().(type) {
case *workflowservice.PauseActivityRequest_Id:
activityIDs = append(activityIDs, a.Id)
case *workflowservice.PauseActivityRequest_Type:
activityType := a.Type
for _, ai := range mutableState.GetPendingActivityInfos() {
if ai.ActivityType.Name == activityType {
activityIDs = append(activityIDs, ai.ActivityId)
}
}
}
if len(activityIDs) == 0 {
return nil, consts.ErrActivityNotFound
}
pauseInfo := &persistencespb.ActivityInfo_PauseInfo{
PauseTime: timestamppb.New(shardContext.GetTimeSource().Now()),
PausedBy: &persistencespb.ActivityInfo_PauseInfo_Manual_{
Manual: &persistencespb.ActivityInfo_PauseInfo_Manual{
Identity: frontendRequest.GetIdentity(),
Reason: frontendRequest.GetReason(),
},
},
}
for _, activityId := range activityIDs {
err := workflow.PauseActivity(mutableState, activityId, pauseInfo)
if err != nil {
return nil, err
}
}
return &api.UpdateWorkflowAction{
Noop: false,
CreateWorkflowTask: false,
}, nil
},
nil,
shardContext,
workflowConsistencyChecker,
)
if err != nil {
return nil, err
}
return &historyservice.PauseActivityResponse{}, nil
}