mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +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.
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package workflow
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
commandpb "go.temporal.io/api/command/v1"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
chasmworkflow "go.temporal.io/server/chasm/lib/workflow"
|
|
historyi "go.temporal.io/server/service/history/interfaces"
|
|
)
|
|
|
|
// ErrDuplicateRegistration is returned by a [CommandHandlerRegistry] when it detects duplicate registration.
|
|
var ErrDuplicateRegistration = errors.New("duplicate registration")
|
|
|
|
// CommandHandler is a function for handling a workflow command as part of processing a RespondWorkflowTaskCompleted
|
|
// worker request.
|
|
type CommandHandler func(
|
|
context.Context,
|
|
historyi.MutableState,
|
|
chasmworkflow.Validator,
|
|
int64,
|
|
*commandpb.Command,
|
|
) error
|
|
|
|
// CommandHandlerRegistry maintains a mapping of command type to [CommandHandler].
|
|
type CommandHandlerRegistry struct {
|
|
handlers map[enumspb.CommandType]CommandHandler
|
|
}
|
|
|
|
// NewCommandHandlerRegistry creates a new [CommandHandlerRegistry].
|
|
func NewCommandHandlerRegistry() *CommandHandlerRegistry {
|
|
return &CommandHandlerRegistry{
|
|
handlers: make(map[enumspb.CommandType]CommandHandler),
|
|
}
|
|
}
|
|
|
|
// Register registers a [CommandHandler] for a given command type.
|
|
// Returns an [ErrDuplicateRegistration] if a handler for the given command is already registered.
|
|
// All registration is expected to happen in a single thread on process initialization.
|
|
func (r *CommandHandlerRegistry) Register(t enumspb.CommandType, handler CommandHandler) error {
|
|
if existing, ok := r.handlers[t]; ok {
|
|
return fmt.Errorf("%w: command handler for %v: %v", ErrDuplicateRegistration, t, existing)
|
|
}
|
|
r.handlers[t] = handler
|
|
return nil
|
|
}
|
|
|
|
// Handler returns a [CommandHandler] for a given type and a boolean indicating whether it was found.
|
|
func (r *CommandHandlerRegistry) Handler(t enumspb.CommandType) (handler CommandHandler, ok bool) {
|
|
handler, ok = r.handlers[t]
|
|
return
|
|
}
|