mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +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`.
175 lines
3.9 KiB
Go
175 lines
3.9 KiB
Go
package scheduler_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
schedulepb "go.temporal.io/api/schedule/v1"
|
|
workflowpb "go.temporal.io/api/workflow/v1"
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/backoff"
|
|
"go.temporal.io/server/components/scheduler"
|
|
"go.temporal.io/server/service/history/hsm"
|
|
"go.temporal.io/server/service/history/hsm/hsmtest"
|
|
"go.temporal.io/server/service/history/workflow"
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
)
|
|
|
|
const (
|
|
namespace = "ns"
|
|
namespaceID = "ns-id"
|
|
scheduleID = "sched-id"
|
|
|
|
defaultInterval = 1 * time.Minute
|
|
defaultCatchupWindow = 5 * time.Minute
|
|
)
|
|
|
|
type (
|
|
fakeEnv struct {
|
|
node *hsm.Node
|
|
now time.Time
|
|
}
|
|
|
|
root struct{}
|
|
)
|
|
|
|
var (
|
|
_ hsm.Environment = fakeEnv{}
|
|
)
|
|
|
|
func (root) IsWorkflowExecutionRunning() bool {
|
|
return true
|
|
}
|
|
|
|
func newFakeEnv() *fakeEnv {
|
|
return &fakeEnv{
|
|
now: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (e fakeEnv) Access(
|
|
ctx context.Context,
|
|
ref hsm.Ref,
|
|
accessType hsm.AccessType,
|
|
accessor func(*hsm.Node) error) error {
|
|
return accessor(e.node)
|
|
}
|
|
|
|
func (e fakeEnv) Now() time.Time {
|
|
return e.now
|
|
}
|
|
|
|
func newRegistry(t *testing.T) *hsm.Registry {
|
|
t.Helper()
|
|
reg := hsm.NewRegistry()
|
|
require.NoError(t, workflow.RegisterStateMachine(reg))
|
|
require.NoError(t, scheduler.RegisterStateMachines(reg))
|
|
return reg
|
|
}
|
|
|
|
func newRoot(t *testing.T, registry *hsm.Registry, backend *hsmtest.NodeBackend) *hsm.Node {
|
|
root, err := hsm.NewRoot(
|
|
registry,
|
|
workflow.StateMachineType,
|
|
root{},
|
|
make(map[string]*persistencespb.StateMachineMap),
|
|
backend,
|
|
)
|
|
require.NoError(t, err)
|
|
return root
|
|
}
|
|
|
|
// newSchedulerTree returns the root node for an initialized Scheduler state
|
|
// machine tree.
|
|
func newSchedulerTree(
|
|
t *testing.T,
|
|
registry *hsm.Registry,
|
|
root *hsm.Node,
|
|
sched *schedulepb.Schedule,
|
|
patch *schedulepb.SchedulePatch,
|
|
) *hsm.Node {
|
|
// Add Scheduler root node
|
|
s := scheduler.NewScheduler(namespace, namespaceID, scheduleID, sched, patch)
|
|
schedulerNode, err := root.AddChild(hsm.Key{
|
|
Type: scheduler.SchedulerMachineType,
|
|
ID: scheduleID,
|
|
}, *s)
|
|
require.NoError(t, err)
|
|
|
|
// Add Generator sub state machine node
|
|
generator := scheduler.NewGenerator()
|
|
_, err = schedulerNode.AddChild(scheduler.GeneratorMachineKey, *generator)
|
|
require.NoError(t, err)
|
|
|
|
// Add Invoker sub state machine node
|
|
invoker := scheduler.NewInvoker()
|
|
_, err = schedulerNode.AddChild(scheduler.InvokerMachineKey, *invoker)
|
|
require.NoError(t, err)
|
|
|
|
// TODO - add others
|
|
|
|
return schedulerNode
|
|
}
|
|
|
|
// defaultSchedule returns a protobuf definition for a schedule matching this
|
|
// package's other testing defaults.
|
|
func defaultSchedule() *schedulepb.Schedule {
|
|
return &schedulepb.Schedule{
|
|
Spec: &schedulepb.ScheduleSpec{
|
|
Interval: []*schedulepb.IntervalSpec{
|
|
{
|
|
Interval: durationpb.New(defaultInterval),
|
|
Phase: durationpb.New(0),
|
|
},
|
|
},
|
|
},
|
|
Action: &schedulepb.ScheduleAction{
|
|
Action: &schedulepb.ScheduleAction_StartWorkflow{
|
|
StartWorkflow: &workflowpb.NewWorkflowExecutionInfo{
|
|
WorkflowId: "scheduled-wf",
|
|
},
|
|
},
|
|
},
|
|
Policies: &schedulepb.SchedulePolicies{
|
|
CatchupWindow: durationpb.New(defaultCatchupWindow),
|
|
},
|
|
State: &schedulepb.ScheduleState{
|
|
Paused: false,
|
|
LimitedActions: false,
|
|
RemainingActions: 0,
|
|
},
|
|
}
|
|
}
|
|
|
|
func defaultConfig() *scheduler.Config {
|
|
return &scheduler.Config{
|
|
Tweakables: func(_ string) scheduler.Tweakables {
|
|
return scheduler.DefaultTweakables
|
|
},
|
|
ServiceCallTimeout: func() time.Duration {
|
|
return 5 * time.Second
|
|
},
|
|
RetryPolicy: func() backoff.RetryPolicy {
|
|
return backoff.NewExponentialRetryPolicy(1 * time.Second)
|
|
},
|
|
}
|
|
}
|
|
|
|
func opLogTasks(node *hsm.Node) (tasks []hsm.Task, err error) {
|
|
opLog, err := node.OpLog()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, op := range opLog {
|
|
output, ok := op.(hsm.TransitionOperation)
|
|
if ok {
|
|
tasks = append(tasks, output.Output.Tasks...)
|
|
}
|
|
}
|
|
|
|
return tasks, nil
|
|
}
|