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).
103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination history_branch_util_mock.go
|
|
|
|
package persistence
|
|
|
|
import (
|
|
"time"
|
|
|
|
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
|
|
"github.com/hanzoai/tasks/common/persistence/serialization"
|
|
"github.com/hanzoai/tasks/common/primitives"
|
|
)
|
|
|
|
type (
|
|
HistoryBranchUtil interface {
|
|
NewHistoryBranch(
|
|
namespaceID string,
|
|
workflowID string,
|
|
runID string,
|
|
treeID string,
|
|
branchID *string,
|
|
ancestors []*persistencespb.HistoryBranchRange,
|
|
runTimeout time.Duration,
|
|
executionTimeout time.Duration,
|
|
retentionDuration time.Duration,
|
|
) ([]byte, error)
|
|
// ParseHistoryBranchInfo parses the history branch for branch information
|
|
ParseHistoryBranchInfo(
|
|
branchToken []byte,
|
|
) (*persistencespb.HistoryBranch, error)
|
|
// UpdateHistoryBranchInfo updates the history branch with branch information
|
|
UpdateHistoryBranchInfo(
|
|
branchToken []byte,
|
|
branchInfo *persistencespb.HistoryBranch,
|
|
runID string,
|
|
) ([]byte, error)
|
|
}
|
|
|
|
HistoryBranchUtilImpl struct {
|
|
serializer serialization.Serializer
|
|
}
|
|
)
|
|
|
|
func NewHistoryBranchUtil(serializer serialization.Serializer) *HistoryBranchUtilImpl {
|
|
return &HistoryBranchUtilImpl{
|
|
serializer: serializer,
|
|
}
|
|
}
|
|
|
|
func (u *HistoryBranchUtilImpl) NewHistoryBranch(
|
|
_ string, // namespaceID
|
|
_ string, // workflowID
|
|
_ string, // runID
|
|
treeID string,
|
|
branchID *string,
|
|
ancestors []*persistencespb.HistoryBranchRange,
|
|
_ time.Duration, // runTimeout
|
|
_ time.Duration, // executionTimeout
|
|
_ time.Duration, // retentionDuration
|
|
) ([]byte, error) {
|
|
var id string
|
|
if branchID == nil {
|
|
id = primitives.NewUUID().String()
|
|
} else {
|
|
id = *branchID
|
|
}
|
|
bi := &persistencespb.HistoryBranch{
|
|
TreeId: treeID,
|
|
BranchId: id,
|
|
Ancestors: ancestors,
|
|
}
|
|
data, err := u.serializer.HistoryBranchToBlob(bi)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return data.Data, nil
|
|
}
|
|
|
|
func (u *HistoryBranchUtilImpl) ParseHistoryBranchInfo(
|
|
branchToken []byte,
|
|
) (*persistencespb.HistoryBranch, error) {
|
|
return u.serializer.HistoryBranchFromBlob(branchToken)
|
|
}
|
|
|
|
func (u *HistoryBranchUtilImpl) UpdateHistoryBranchInfo(
|
|
branchToken []byte,
|
|
branchInfo *persistencespb.HistoryBranch,
|
|
runID string,
|
|
) ([]byte, error) {
|
|
bi, err := u.serializer.HistoryBranchFromBlob(branchToken)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bi.TreeId = branchInfo.TreeId
|
|
bi.BranchId = branchInfo.BranchId
|
|
bi.Ancestors = branchInfo.Ancestors
|
|
|
|
blob, err := u.serializer.HistoryBranchToBlob(bi)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return blob.Data, nil
|
|
}
|