Files
tasks/service/history/hsm/hsmtest/sm.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

98 lines
1.6 KiB
Go

package hsmtest
import (
"fmt"
"strings"
"time"
"github.com/hanzoai/tasks/service/history/hsm"
)
var (
errInvalidStateType = fmt.Errorf("invalid state type")
)
type State string
const (
State1 State = "state1"
State2 State = "state2"
State3 State = "state3"
State4 State = "state4"
)
type Data struct {
state State
}
func NewData(
state State,
) *Data {
return &Data{
state: state,
}
}
func (d *Data) State() State {
return d.state
}
func (d *Data) SetState(s State) {
d.state = s
}
func (d *Data) RegenerateTasks(node *hsm.Node) ([]hsm.Task, error) {
return []hsm.Task{
NewTask(
hsm.TaskAttributes{Deadline: time.Now().Add(time.Hour)},
false,
),
NewTask(
hsm.TaskAttributes{Destination: string(d.state)},
false,
),
}, nil
}
type Definition struct {
typeName string
}
func NewDefinition(typeName string) Definition {
return Definition{
typeName: typeName,
}
}
func (d Definition) Deserialize(b []byte) (any, error) {
return &Data{State(string(b))}, nil
}
// Serialize implements hsm.StateMachineDefinition.
func (d Definition) Serialize(s any) ([]byte, error) {
t, ok := s.(*Data)
if !ok {
return nil, errInvalidStateType
}
return []byte(t.state), nil
}
// Type implements hsm.StateMachineDefinition.
func (d Definition) Type() string {
return d.typeName
}
func (d Definition) CompareState(s1 any, s2 any) (int, error) {
t1, ok := s1.(*Data)
if !ok {
return 0, errInvalidStateType
}
t2, ok := s2.(*Data)
if !ok {
return 0, errInvalidStateType
}
return strings.Compare(string(t1.State()), string(t2.State())), nil
}