Files
tasks/service/history/hsm/hsmtest/task.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.2 KiB
Go

package hsmtest
import (
"encoding/json"
"fmt"
"time"
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
"github.com/hanzoai/tasks/service/history/hsm"
)
const TaskType = "test-task-type-name"
var (
errInvalidTaskType = fmt.Errorf("invalid task type")
)
type Task struct {
attrs hsm.TaskAttributes
IsConcurrent bool
}
func NewTask(
attrs hsm.TaskAttributes,
concurrent bool,
) *Task {
return &Task{
attrs: attrs,
IsConcurrent: concurrent,
}
}
func (t *Task) Type() string {
return TaskType
}
func (t *Task) Deadline() time.Time {
return t.attrs.Deadline
}
func (t *Task) Destination() string {
return t.attrs.Destination
}
func (t *Task) Validate(ref *persistencespb.StateMachineRef, node *hsm.Node) error {
if t.IsConcurrent {
return hsm.ValidateNotTransitioned(ref, node)
}
return nil
}
type TaskSerializer struct{}
func (s TaskSerializer) Serialize(t hsm.Task) ([]byte, error) {
if t.Type() != TaskType {
return nil, errInvalidTaskType
}
return json.Marshal(t)
}
func (s TaskSerializer) Deserialize(b []byte, attrs hsm.TaskAttributes) (hsm.Task, error) {
var t Task
if err := json.Unmarshal(b, &t); err != nil {
return nil, err
}
t.attrs = attrs
return &t, nil
}