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).
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/tasks/chasm"
|
|
"github.com/hanzoai/tasks/chasm/lib/tests/gen/testspb/v1"
|
|
)
|
|
|
|
type (
|
|
PayloadTTLPureTaskExecutor struct{}
|
|
PayloadTTLPureTaskValidator struct{}
|
|
)
|
|
|
|
func (e *PayloadTTLPureTaskExecutor) Execute(
|
|
mutableContext chasm.MutableContext,
|
|
store *PayloadStore,
|
|
_ chasm.TaskAttributes,
|
|
task *testspb.TestPayloadTTLPureTask,
|
|
) error {
|
|
if err := assertContextValue(mutableContext); err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err := store.RemovePayload(mutableContext, task.PayloadKey)
|
|
return err
|
|
}
|
|
|
|
func (v *PayloadTTLPureTaskValidator) Validate(
|
|
chasmContext chasm.Context,
|
|
store *PayloadStore,
|
|
attributes chasm.TaskAttributes,
|
|
task *testspb.TestPayloadTTLPureTask,
|
|
) (bool, error) {
|
|
return validateTask(chasmContext, store, attributes, task.PayloadKey)
|
|
}
|
|
|
|
type (
|
|
PayloadTTLSideEffectTaskExecutor struct{}
|
|
PayloadTTLSideEffectTaskValidator struct{}
|
|
)
|
|
|
|
func (e *PayloadTTLSideEffectTaskExecutor) Execute(
|
|
ctx context.Context,
|
|
ref chasm.ComponentRef,
|
|
_ chasm.TaskAttributes,
|
|
task *testspb.TestPayloadTTLSideEffectTask,
|
|
) error {
|
|
_, _, err := chasm.UpdateComponent(
|
|
ctx,
|
|
ref,
|
|
(*PayloadStore).RemovePayload,
|
|
task.PayloadKey,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func (v *PayloadTTLSideEffectTaskValidator) Validate(
|
|
chasmContext chasm.Context,
|
|
store *PayloadStore,
|
|
attributes chasm.TaskAttributes,
|
|
task *testspb.TestPayloadTTLSideEffectTask,
|
|
) (bool, error) {
|
|
return validateTask(chasmContext, store, attributes, task.PayloadKey)
|
|
}
|
|
|
|
func validateTask(
|
|
chasmContext chasm.Context,
|
|
store *PayloadStore,
|
|
attributes chasm.TaskAttributes,
|
|
payloadKey string,
|
|
) (bool, error) {
|
|
if err := assertContextValue(chasmContext); err != nil {
|
|
return false, err
|
|
}
|
|
|
|
expirationTime, ok := store.State.ExpirationTimes[payloadKey]
|
|
if !ok {
|
|
return false, nil
|
|
}
|
|
|
|
return !expirationTime.AsTime().After(attributes.ScheduledTime), nil
|
|
}
|