Files
tasks/components/callbacks/tasks.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

95 lines
2.3 KiB
Go

package callbacks
import (
"time"
enumsspb "github.com/hanzoai/tasks/api/enums/v1"
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
"github.com/hanzoai/tasks/service/history/hsm"
)
const (
TaskTypeInvocation = "callbacks.Invocation"
TaskTypeBackoff = "callbacks.Backoff"
)
type InvocationTask struct {
// The base URL for nexus callbacks.
// Will have other meanings as more callback use cases are added.
destination string
}
var _ hsm.Task = InvocationTask{}
func NewInvocationTask(destination string) InvocationTask {
return InvocationTask{destination: destination}
}
func (InvocationTask) Type() string {
return TaskTypeInvocation
}
func (t InvocationTask) Destination() string {
return t.destination
}
func (t InvocationTask) Deadline() time.Time {
return hsm.Immediate
}
func (InvocationTask) Validate(ref *persistencespb.StateMachineRef, node *hsm.Node) error {
return hsm.ValidateState[enumsspb.CallbackState, Callback](node, enumsspb.CALLBACK_STATE_SCHEDULED)
}
type InvocationTaskSerializer struct{}
func (InvocationTaskSerializer) Deserialize(data []byte, attrs hsm.TaskAttributes) (hsm.Task, error) {
return InvocationTask{destination: attrs.Destination}, nil
}
func (InvocationTaskSerializer) Serialize(hsm.Task) ([]byte, error) {
return nil, nil
}
type BackoffTask struct {
deadline time.Time
}
var _ hsm.Task = BackoffTask{}
func (BackoffTask) Type() string {
return TaskTypeBackoff
}
func (t BackoffTask) Deadline() time.Time {
return t.deadline
}
func (BackoffTask) Destination() string {
return ""
}
func (BackoffTask) Validate(ref *persistencespb.StateMachineRef, node *hsm.Node) error {
return hsm.ValidateState[enumsspb.CallbackState, Callback](node, enumsspb.CALLBACK_STATE_BACKING_OFF)
}
type BackoffTaskSerializer struct{}
func (BackoffTaskSerializer) Deserialize(data []byte, attrs hsm.TaskAttributes) (hsm.Task, error) {
return BackoffTask{deadline: attrs.Deadline}, nil
}
func (BackoffTaskSerializer) Serialize(hsm.Task) ([]byte, error) {
return nil, nil
}
func RegisterTaskSerializers(reg *hsm.Registry) error {
if err := reg.RegisterTaskSerializer(TaskTypeInvocation, InvocationTaskSerializer{}); err != nil {
return err
}
if err := reg.RegisterTaskSerializer(TaskTypeBackoff, BackoffTaskSerializer{}); err != nil { // nolint:revive
return err
}
return nil
}