mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
107 lines
2.8 KiB
Go
107 lines
2.8 KiB
Go
package unpauseactivity
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"github.com/hanzoai/tasks/api/historyservice/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"
|
|
)
|
|
|
|
func Invoke(
|
|
ctx context.Context,
|
|
request *historyservice.UnpauseActivityRequest,
|
|
shardContext historyi.ShardContext,
|
|
workflowConsistencyChecker api.WorkflowConsistencyChecker,
|
|
) (resp *historyservice.UnpauseActivityResponse, retError error) {
|
|
var response *historyservice.UnpauseActivityResponse
|
|
|
|
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()
|
|
var err error
|
|
response, err = processUnpauseActivityRequest(shardContext, mutableState, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &api.UpdateWorkflowAction{
|
|
Noop: false,
|
|
CreateWorkflowTask: false,
|
|
}, nil
|
|
},
|
|
nil,
|
|
shardContext,
|
|
workflowConsistencyChecker,
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return response, err
|
|
}
|
|
|
|
func processUnpauseActivityRequest(
|
|
shardContext historyi.ShardContext,
|
|
mutableState historyi.MutableState,
|
|
request *historyservice.UnpauseActivityRequest,
|
|
) (*historyservice.UnpauseActivityResponse, error) {
|
|
|
|
if !mutableState.IsWorkflowExecutionRunning() {
|
|
return nil, consts.ErrWorkflowCompleted
|
|
}
|
|
frontendRequest := request.GetFrontendRequest()
|
|
var activityIDs []string
|
|
switch a := frontendRequest.GetActivity().(type) {
|
|
case *workflowservice.UnpauseActivityRequest_Id:
|
|
activityIDs = append(activityIDs, a.Id)
|
|
case *workflowservice.UnpauseActivityRequest_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
|
|
}
|
|
|
|
for _, activityId := range activityIDs {
|
|
|
|
ai, activityFound := mutableState.GetActivityByActivityID(activityId)
|
|
|
|
if !activityFound {
|
|
return nil, consts.ErrActivityNotFound
|
|
}
|
|
|
|
if !ai.Paused {
|
|
// do nothing
|
|
continue
|
|
}
|
|
|
|
if err := workflow.UnpauseActivity(
|
|
shardContext, mutableState, ai,
|
|
frontendRequest.GetResetAttempts(),
|
|
frontendRequest.GetResetHeartbeat(),
|
|
frontendRequest.GetJitter().AsDuration()); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
}
|
|
|
|
return &historyservice.UnpauseActivityResponse{}, nil
|
|
}
|