mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.
Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)
New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.
Build: go build ./cmd/tasksd → 10 MB
Vet: go vet ./... → clean
Boot: tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI: /_/tasks/, / → 200 (embedded Vite bundle)
ZAP: _tasks._tcp on :9999 (mDNS disabled; direct connect)
go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
126 lines
3.5 KiB
Go
126 lines
3.5 KiB
Go
package scheduler_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.temporal.io/server/chasm"
|
|
"go.temporal.io/server/chasm/lib/scheduler"
|
|
"go.temporal.io/server/chasm/lib/scheduler/gen/schedulerpb/v1"
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
type idleValidateTestCase struct {
|
|
configIdleTime time.Duration
|
|
taskIdleTimeTotal time.Duration
|
|
scheduledTime time.Time
|
|
schedulerClosed bool
|
|
idleMatchesScheduledTime bool
|
|
setupScheduler func(*scheduler.Scheduler, chasm.Context)
|
|
expectedValid bool
|
|
}
|
|
|
|
func runIdleValidateTestCase(t *testing.T, env *testEnv, c *idleValidateTestCase) {
|
|
ctx := env.MutableContext()
|
|
sched := env.Scheduler
|
|
|
|
sched.Closed = c.schedulerClosed
|
|
|
|
if c.setupScheduler != nil {
|
|
c.setupScheduler(sched, ctx)
|
|
}
|
|
|
|
config := &scheduler.Config{
|
|
Tweakables: func(_ string) scheduler.Tweakables {
|
|
tweakables := scheduler.DefaultTweakables
|
|
tweakables.IdleTime = c.configIdleTime
|
|
return tweakables
|
|
},
|
|
}
|
|
|
|
handler := scheduler.NewSchedulerIdleTaskHandler(scheduler.SchedulerIdleTaskHandlerOptions{
|
|
Config: config,
|
|
})
|
|
|
|
task := &schedulerpb.SchedulerIdleTask{
|
|
IdleTimeTotal: durationpb.New(c.taskIdleTimeTotal),
|
|
}
|
|
|
|
scheduledTime := c.scheduledTime
|
|
if c.idleMatchesScheduledTime {
|
|
lastEventTime := scheduledTime.Add(-c.configIdleTime)
|
|
sched.Info.UpdateTime = timestamppb.New(lastEventTime)
|
|
sched.Info.CreateTime = timestamppb.New(lastEventTime)
|
|
}
|
|
|
|
taskAttrs := chasm.TaskAttributes{
|
|
ScheduledTime: scheduledTime,
|
|
}
|
|
|
|
isValid, err := handler.Validate(ctx, sched, taskAttrs, task)
|
|
require.NoError(t, err)
|
|
require.Equal(t, c.expectedValid, isValid)
|
|
}
|
|
|
|
func TestIdleTask_Execute(t *testing.T) {
|
|
env := newTestEnv(t)
|
|
ctx := env.MutableContext()
|
|
sched := env.Scheduler
|
|
|
|
handler := scheduler.NewSchedulerIdleTaskHandler(scheduler.SchedulerIdleTaskHandlerOptions{
|
|
Config: defaultConfig(),
|
|
})
|
|
|
|
// Verify scheduler starts open.
|
|
require.False(t, sched.Closed)
|
|
|
|
// Execute the idle task.
|
|
err := handler.Execute(ctx, sched, chasm.TaskAttributes{}, &schedulerpb.SchedulerIdleTask{})
|
|
require.NoError(t, err)
|
|
|
|
// Verify scheduler is now closed.
|
|
require.True(t, sched.Closed)
|
|
}
|
|
|
|
func TestIdleTask_Validate_SchedulerNotIdle(t *testing.T) {
|
|
env := newTestEnv(t)
|
|
now := env.TimeSource.Now()
|
|
runIdleValidateTestCase(t, env, &idleValidateTestCase{
|
|
configIdleTime: 10 * time.Minute,
|
|
taskIdleTimeTotal: 10 * time.Minute,
|
|
scheduledTime: now,
|
|
setupScheduler: func(sched *scheduler.Scheduler, ctx chasm.Context) {
|
|
// Make scheduler not idle by setting it as paused.
|
|
sched.Schedule.State.Paused = true
|
|
},
|
|
expectedValid: false,
|
|
})
|
|
}
|
|
|
|
func TestIdleTask_Validate_ValidIdleTask(t *testing.T) {
|
|
env := newTestEnv(t)
|
|
now := env.TimeSource.Now()
|
|
runIdleValidateTestCase(t, env, &idleValidateTestCase{
|
|
configIdleTime: 10 * time.Minute,
|
|
taskIdleTimeTotal: 10 * time.Minute,
|
|
scheduledTime: now,
|
|
idleMatchesScheduledTime: true,
|
|
expectedValid: true,
|
|
})
|
|
}
|
|
|
|
func TestIdleTask_Validate_SchedulerAlreadyClosed(t *testing.T) {
|
|
env := newTestEnv(t)
|
|
now := env.TimeSource.Now()
|
|
runIdleValidateTestCase(t, env, &idleValidateTestCase{
|
|
configIdleTime: 10 * time.Minute,
|
|
taskIdleTimeTotal: 10 * time.Minute,
|
|
scheduledTime: now,
|
|
schedulerClosed: true,
|
|
idleMatchesScheduledTime: true,
|
|
expectedValid: false, // Should return !scheduler.Closed (false when closed).
|
|
})
|
|
}
|