mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
Rename SideEffectTaskExecutor to SideEffectTaskHandler and PureTaskExecutor to PureTaskHandler across the CHASM framework and all library implementations (activity, callback, nexusoperation, scheduler). Merge the separate SideEffectTaskDiscarder interface into SideEffectTaskHandler as a required Discard method. Introduce SideEffectTaskHandlerBase[T] which provides a default Discard returning ErrTaskDiscarded, and PureTaskHandlerBase with an unexported marker method — both must be embedded by implementations. This eliminates HasDiscardHandler() from RegistrableTask and the conditional nil check in ExecuteSideEffectDiscardTask, replacing it with eager validation that rejects pure tasks at the call site. The discard function is now always present on side-effect tasks, simplifying the standby task execution path. Also rename executor source files to tasks files in the callback and nexusoperation packages and update receiver names from `e` to `h` throughout. ## Why? - The split interfaces required duplicate registration but in practice both interfaces were implemented by a single struct. - A base implementation is great for future proofing when more optional methods are added.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package history
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.temporal.io/server/chasm"
|
|
)
|
|
|
|
// discardableTaskTestLibrary is a minimal CHASM library that registers a side-effect task whose handler has a custom
|
|
// Discard implementation, used for testing discard paths in standby task executors.
|
|
type discardableTaskTestLibrary struct {
|
|
chasm.UnimplementedLibrary
|
|
}
|
|
|
|
func (l *discardableTaskTestLibrary) Name() string { return "DiscardableTestLib" }
|
|
|
|
func (l *discardableTaskTestLibrary) Tasks() []*chasm.RegistrableTask {
|
|
return []*chasm.RegistrableTask{
|
|
chasm.NewRegistrableSideEffectTask(
|
|
"discard_task",
|
|
&discardableTestTaskHandler{},
|
|
),
|
|
}
|
|
}
|
|
|
|
type discardableTestTask struct{}
|
|
|
|
type discardableTestTaskHandler struct {
|
|
chasm.SideEffectTaskHandlerBase[*discardableTestTask]
|
|
}
|
|
|
|
func (e *discardableTestTaskHandler) Validate(_ chasm.Context, _ any, _ chasm.TaskAttributes, _ *discardableTestTask) (bool, error) {
|
|
return true, nil
|
|
}
|
|
|
|
func (e *discardableTestTaskHandler) Execute(_ context.Context, _ chasm.ComponentRef, _ chasm.TaskAttributes, _ *discardableTestTask) error {
|
|
return nil
|
|
}
|
|
|
|
func (e *discardableTestTaskHandler) Discard(_ context.Context, _ chasm.ComponentRef, _ chasm.TaskAttributes, _ *discardableTestTask) error {
|
|
return nil
|
|
}
|
|
|
|
// nonDiscardableTaskTestLibrary is a minimal CHASM library that registers a side-effect task whose handler uses the
|
|
// default Discard from SideEffectTaskHandlerBase (returns ErrTaskDiscarded).
|
|
type nonDiscardableTaskTestLibrary struct {
|
|
chasm.UnimplementedLibrary
|
|
}
|
|
|
|
func (l *nonDiscardableTaskTestLibrary) Name() string { return "NonDiscardableTestLib" }
|
|
|
|
func (l *nonDiscardableTaskTestLibrary) Tasks() []*chasm.RegistrableTask {
|
|
return []*chasm.RegistrableTask{
|
|
chasm.NewRegistrableSideEffectTask(
|
|
"non_discard_task",
|
|
&nonDiscardableTestTaskHandler{},
|
|
),
|
|
}
|
|
}
|
|
|
|
type nonDiscardableTestTask struct{}
|
|
|
|
type nonDiscardableTestTaskHandler struct {
|
|
chasm.SideEffectTaskHandlerBase[*nonDiscardableTestTask]
|
|
}
|
|
|
|
func (e *nonDiscardableTestTaskHandler) Validate(_ chasm.Context, _ any, _ chasm.TaskAttributes, _ *nonDiscardableTestTask) (bool, error) {
|
|
return true, nil
|
|
}
|
|
|
|
func (e *nonDiscardableTestTaskHandler) Execute(_ context.Context, _ chasm.ComponentRef, _ chasm.TaskAttributes, _ *nonDiscardableTestTask) error {
|
|
return nil
|
|
}
|