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.
103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
package scheduler
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.temporal.io/api/serviceerror"
|
|
schedulerpb "go.temporal.io/server/chasm/lib/scheduler/gen/schedulerpb/v1"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/namespace"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type mockSchedulerClient struct {
|
|
schedulerpb.SchedulerServiceClient
|
|
migrateErr error
|
|
}
|
|
|
|
func (m *mockSchedulerClient) CreateFromMigrationState(
|
|
_ context.Context,
|
|
_ *schedulerpb.CreateFromMigrationStateRequest,
|
|
_ ...grpc.CallOption,
|
|
) (*schedulerpb.CreateFromMigrationStateResponse, error) {
|
|
return &schedulerpb.CreateFromMigrationStateResponse{}, m.migrateErr
|
|
}
|
|
|
|
func newTestActivities(client schedulerpb.SchedulerServiceClient, nsID namespace.ID) *activities {
|
|
return &activities{
|
|
activityDeps: activityDeps{
|
|
Logger: log.NewNoopLogger(),
|
|
SchedulerClient: client,
|
|
MetricsHandler: metrics.NoopMetricsHandler,
|
|
},
|
|
namespaceID: nsID,
|
|
}
|
|
}
|
|
|
|
const testNamespaceID = "test-namespace-id"
|
|
|
|
func TestMigrateScheduleToChasm_Success(t *testing.T) {
|
|
client := &mockSchedulerClient{}
|
|
a := newTestActivities(client, testNamespaceID)
|
|
|
|
err := a.MigrateScheduleToChasm(context.Background(), &schedulerpb.CreateFromMigrationStateRequest{
|
|
NamespaceId: testNamespaceID,
|
|
})
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestMigrateScheduleToChasm_AlreadyExists(t *testing.T) {
|
|
client := &mockSchedulerClient{
|
|
migrateErr: serviceerror.NewAlreadyExistsf("schedule %q is already registered", "test-schedule"),
|
|
}
|
|
a := newTestActivities(client, testNamespaceID)
|
|
|
|
err := a.MigrateScheduleToChasm(context.Background(), &schedulerpb.CreateFromMigrationStateRequest{
|
|
NamespaceId: testNamespaceID,
|
|
})
|
|
require.NoError(t, err, "already-exists should be treated as success")
|
|
}
|
|
|
|
func TestMigrateScheduleToChasm_SentinelBlocked(t *testing.T) {
|
|
client := &mockSchedulerClient{
|
|
migrateErr: serviceerror.NewUnavailable("schedule is a sentinel; please retry after sentinel expires"),
|
|
}
|
|
a := newTestActivities(client, testNamespaceID)
|
|
|
|
err := a.MigrateScheduleToChasm(context.Background(), &schedulerpb.CreateFromMigrationStateRequest{
|
|
NamespaceId: testNamespaceID,
|
|
})
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "blocked by sentinel")
|
|
}
|
|
|
|
func TestMigrateScheduleToChasm_OtherError(t *testing.T) {
|
|
client := &mockSchedulerClient{
|
|
migrateErr: errors.New("some transient error"),
|
|
}
|
|
a := newTestActivities(client, testNamespaceID)
|
|
|
|
err := a.MigrateScheduleToChasm(context.Background(), &schedulerpb.CreateFromMigrationStateRequest{
|
|
NamespaceId: testNamespaceID,
|
|
})
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "MigrateScheduleToChasm")
|
|
}
|
|
|
|
func TestMigrateScheduleToChasm_NamespaceMismatch(t *testing.T) {
|
|
client := &mockSchedulerClient{}
|
|
a := newTestActivities(client, testNamespaceID)
|
|
|
|
err := a.MigrateScheduleToChasm(context.Background(), &schedulerpb.CreateFromMigrationStateRequest{
|
|
NamespaceId: "different-namespace-id",
|
|
})
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "namespace_mismatch")
|
|
require.Contains(t, err.Error(), "different-namespace-id")
|
|
require.Contains(t, err.Error(), testNamespaceID)
|
|
}
|