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).
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package isactivitytaskvalid
|
|
|
|
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.IsActivityTaskValidRequest,
|
|
shardContext historyi.ShardContext,
|
|
workflowConsistencyChecker api.WorkflowConsistencyChecker,
|
|
) (resp *historyservice.IsActivityTaskValidResponse, 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 := isActivityTaskValid(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.IsActivityTaskValidResponse{
|
|
IsValid: isValid,
|
|
}, err
|
|
}
|
|
|
|
func isActivityTaskValid(
|
|
workflowLease api.WorkflowLease,
|
|
scheduledEventID int64,
|
|
stamp int32,
|
|
) (bool, error) {
|
|
mutableState := workflowLease.GetMutableState()
|
|
if !mutableState.IsWorkflowExecutionRunning() {
|
|
return false, consts.ErrWorkflowCompleted
|
|
}
|
|
|
|
ai, ok := mutableState.GetActivityInfo(scheduledEventID)
|
|
if ok && ai.StartedEventId == common.EmptyEventID && ai.GetStamp() == stamp {
|
|
return true, nil
|
|
}
|
|
return false, nil
|
|
}
|