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

69 lines
1.8 KiB
Go

package isworkflowtaskvalid
import (
"context"
"github.com/hanzoai/tasks/api/historyservice/v1"
"github.com/hanzoai/tasks/common"
"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"
)
func Invoke(
ctx context.Context,
req *historyservice.IsWorkflowTaskValidRequest,
shardContext historyi.ShardContext,
workflowConsistencyChecker api.WorkflowConsistencyChecker,
) (resp *historyservice.IsWorkflowTaskValidResponse, retError error) {
isValid := false
err := api.GetAndUpdateWorkflowWithNew(
ctx,
req.Clock,
definition.NewWorkflowKey(
req.NamespaceId,
req.Execution.WorkflowId,
req.Execution.RunId,
),
func(workflowLease api.WorkflowLease) (*api.UpdateWorkflowAction, error) {
isTaskValid, err := isWorkflowTaskValid(workflowLease, req.ScheduledEventId, req.GetStamp())
if err != nil {
return nil, err
}
isValid = isTaskValid
return &api.UpdateWorkflowAction{
Noop: true,
CreateWorkflowTask: false,
}, nil
},
nil,
shardContext,
workflowConsistencyChecker,
)
return &historyservice.IsWorkflowTaskValidResponse{
IsValid: isValid,
}, err
}
func isWorkflowTaskValid(
workflowLease api.WorkflowLease,
scheduledEventID int64,
stamp int32,
) (bool, error) {
mutableState := workflowLease.GetMutableState()
if !mutableState.IsWorkflowExecutionRunning() {
return false, consts.ErrWorkflowCompleted
}
workflowTask := mutableState.GetWorkflowTaskByID(scheduledEventID)
if workflowTask == nil {
return false, nil
}
if stamp != workflowTask.Stamp {
// This happens when the workflow task was rescheduled.
return false, nil
}
return workflowTask.StartedEventID == common.EmptyEventID, nil
}