mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-02 12:22:18 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package hsm
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/definition"
|
|
)
|
|
|
|
// Ref is a reference to a statemachine on a specific workflow.
|
|
// It contains the workflow key and the key of the statemachine in the state machine [Environment] as well as the
|
|
// information to perform staleness checks for itself or the state that it is referencing.
|
|
type Ref struct {
|
|
WorkflowKey definition.WorkflowKey
|
|
StateMachineRef *persistencespb.StateMachineRef
|
|
// If non-zero, this field represents the ID of the task this Ref came from. Used for stale task detection and
|
|
// serves as an indicator whether this Ref can reference stale state. This should be set during task processing
|
|
// where we can validate the task that embeds this reference against shard clock.
|
|
TaskID int64
|
|
|
|
// An optional function to validate the ref is not stale.
|
|
// For tasks, this is copied from the task's Validate() implementation.
|
|
Validate func(ref *persistencespb.StateMachineRef, node *Node) error
|
|
}
|
|
|
|
// StateMachinePath gets the state machine path for from this reference.
|
|
func (r Ref) StateMachinePath() []Key {
|
|
path := make([]Key, len(r.StateMachineRef.Path))
|
|
for i, k := range r.StateMachineRef.Path {
|
|
path[i] = Key{Type: k.Type, ID: k.Id}
|
|
}
|
|
return path
|
|
}
|
|
|
|
// AccessType is a specifier for storage access.
|
|
type AccessType int
|
|
|
|
const (
|
|
// AccessRead specifies read access.
|
|
AccessRead AccessType = iota
|
|
// AccessWrite specifies write access.
|
|
AccessWrite AccessType = iota
|
|
)
|
|
|
|
// Executor environment.
|
|
type Environment interface {
|
|
// Wall clock. Backed by a the shard's time source.
|
|
Now() time.Time
|
|
// Access a state machine Node for the given ref.
|
|
//
|
|
// When using AccessRead, the accessor must guarantee not to mutate any state, accessor errors will not cause
|
|
// mutable state unload.
|
|
Access(ctx context.Context, ref Ref, accessType AccessType, accessor func(*Node) error) error
|
|
}
|
|
|
|
// ImmediateExecutor is responsible for executing immediate tasks (e.g: transfer, outbound).
|
|
// Implementations should be registered via [RegisterImmediateExecutors] to handle specific task types.
|
|
type ImmediateExecutor[T Task] func(ctx context.Context, env Environment, ref Ref, task T) error
|
|
|
|
// TimerExecutor is responsible for executing timer tasks.
|
|
// Implementations should be registered via [RegisterTimerExecutors] to handle specific task types.
|
|
// Timers tasks are collapsed into a single task which will execute all timers that have hit their deadline while
|
|
// holding a lock on the workflow.
|
|
type TimerExecutor[T Task] func(env Environment, node *Node, task T) error
|
|
|
|
// RemoteExecutor is responsible for executing remote methods.
|
|
// // Implementations should be registered via [RegisterRemoteExecutors] to handle specific methods.
|
|
type RemoteExecutor func(ctx context.Context, env Environment, ref Ref, input any) (any, error)
|