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).
101 lines
2.1 KiB
Go
101 lines
2.1 KiB
Go
package dummy
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
|
|
"github.com/hanzoai/tasks/service/history/hsm"
|
|
)
|
|
|
|
const (
|
|
TaskTypeTimer = "dummy.Timer"
|
|
TaskTypeImmediate = "dummy.Immediate"
|
|
)
|
|
|
|
type ImmediateTask struct {
|
|
destination string
|
|
}
|
|
|
|
var _ hsm.Task = ImmediateTask{}
|
|
|
|
func (ImmediateTask) Type() string {
|
|
return TaskTypeImmediate
|
|
}
|
|
|
|
func (ImmediateTask) Deadline() time.Time {
|
|
return hsm.Immediate
|
|
}
|
|
|
|
func (t ImmediateTask) Destination() string {
|
|
return t.destination
|
|
}
|
|
|
|
func (ImmediateTask) Validate(ref *persistencespb.StateMachineRef, node *hsm.Node) error {
|
|
return hsm.ValidateNotTransitioned(ref, node)
|
|
}
|
|
|
|
type ImmediateTaskSerializer struct{}
|
|
|
|
func (ImmediateTaskSerializer) Deserialize(data []byte, attrs hsm.TaskAttributes) (hsm.Task, error) {
|
|
return ImmediateTask{destination: attrs.Destination}, nil
|
|
}
|
|
|
|
func (ImmediateTaskSerializer) Serialize(hsm.Task) ([]byte, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type TimerTask struct {
|
|
deadline time.Time
|
|
concurrent bool
|
|
}
|
|
|
|
var _ hsm.Task = TimerTask{}
|
|
|
|
func (TimerTask) Type() string {
|
|
return TaskTypeTimer
|
|
}
|
|
|
|
func (t TimerTask) Deadline() time.Time {
|
|
return t.deadline
|
|
}
|
|
|
|
func (TimerTask) Destination() string {
|
|
return ""
|
|
}
|
|
|
|
func (t TimerTask) Validate(ref *persistencespb.StateMachineRef, node *hsm.Node) error {
|
|
if !t.concurrent {
|
|
return hsm.ValidateNotTransitioned(ref, node)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type TimerTaskSerializer struct{}
|
|
|
|
func (TimerTaskSerializer) Deserialize(data []byte, attrs hsm.TaskAttributes) (hsm.Task, error) {
|
|
return TimerTask{deadline: attrs.Deadline, concurrent: len(data) > 0}, nil
|
|
}
|
|
|
|
func (s TimerTaskSerializer) Serialize(task hsm.Task) ([]byte, error) {
|
|
if tt, ok := task.(TimerTask); ok {
|
|
if tt.concurrent {
|
|
// Non empty data marks the task as concurrent.
|
|
return []byte{1}, nil
|
|
}
|
|
// No-op.
|
|
return nil, nil
|
|
}
|
|
return nil, fmt.Errorf("incompatible task: %v", task)
|
|
}
|
|
|
|
func RegisterTaskSerializers(reg *hsm.Registry) error {
|
|
if err := reg.RegisterTaskSerializer(
|
|
TaskTypeImmediate,
|
|
ImmediateTaskSerializer{},
|
|
); err != nil {
|
|
return err
|
|
}
|
|
return reg.RegisterTaskSerializer(TaskTypeTimer, TimerTaskSerializer{})
|
|
}
|