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).
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package hsmtest
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"slices"
|
|
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
historypb "go.temporal.io/api/history/v1"
|
|
tokenspb "github.com/hanzoai/tasks/api/token/v1"
|
|
"github.com/hanzoai/tasks/service/history/hsm"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type NodeBackend struct {
|
|
Events []*historypb.HistoryEvent
|
|
}
|
|
|
|
func (n *NodeBackend) GetCurrentVersion() int64 {
|
|
return 1
|
|
}
|
|
|
|
func (n *NodeBackend) NextTransitionCount() int64 {
|
|
return 3
|
|
}
|
|
|
|
func (n *NodeBackend) AddHistoryEvent(t enumspb.EventType, setAttributes func(*historypb.HistoryEvent)) *historypb.HistoryEvent {
|
|
event := &historypb.HistoryEvent{EventType: t, EventId: 2}
|
|
setAttributes(event)
|
|
n.Events = append(n.Events, event)
|
|
return event
|
|
}
|
|
|
|
func (n *NodeBackend) GenerateEventLoadToken(event *historypb.HistoryEvent) ([]byte, error) {
|
|
token := &tokenspb.HistoryEventRef{
|
|
EventId: event.EventId,
|
|
EventBatchId: event.EventId,
|
|
}
|
|
return proto.Marshal(token)
|
|
}
|
|
|
|
func (n *NodeBackend) LoadHistoryEvent(ctx context.Context, tokenBytes []byte) (*historypb.HistoryEvent, error) {
|
|
var token tokenspb.HistoryEventRef
|
|
if err := proto.Unmarshal(tokenBytes, &token); err != nil {
|
|
return nil, err
|
|
}
|
|
idx := slices.IndexFunc(n.Events, func(event *historypb.HistoryEvent) bool {
|
|
return event.EventId == token.EventId
|
|
})
|
|
|
|
if idx < 0 {
|
|
return nil, fmt.Errorf("event not found")
|
|
}
|
|
|
|
return n.Events[idx], nil
|
|
}
|
|
|
|
var _ hsm.NodeBackend = &NodeBackend{}
|