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.
161 lines
5.4 KiB
Go
161 lines
5.4 KiB
Go
package workerdeployment
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
wciclient "go.temporal.io/auto-scaled-workers/wci/client"
|
|
sdkworker "go.temporal.io/sdk/worker"
|
|
"go.temporal.io/sdk/workflow"
|
|
deploymentspb "go.temporal.io/server/api/deployment/v1"
|
|
"go.temporal.io/server/common/cache"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
"go.temporal.io/server/common/resource"
|
|
"go.temporal.io/server/common/sdk"
|
|
"go.temporal.io/server/common/testing/testhooks"
|
|
workercommon "go.temporal.io/server/service/worker/common"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type DeploymentWorkflowVersion int64
|
|
|
|
const (
|
|
// Versions of workflow logic. When introducing a new version, consider generating a new
|
|
// history for TestReplays using generate_history.sh.
|
|
|
|
// Represents the state before the versioning API's received the option of becoming async in nature
|
|
InitialVersion DeploymentWorkflowVersion = iota
|
|
// SetCurrent and SetRamping and DeleteVersion APIs are async
|
|
AsyncSetCurrentAndRamping
|
|
// Version Data has its own revision number with TaskQueue registration being async as well
|
|
VersionDataRevisionNumber
|
|
)
|
|
|
|
type (
|
|
workerComponent struct {
|
|
activityDeps activityDeps
|
|
dynamicConfig *dynamicconfig.Collection
|
|
}
|
|
|
|
activityDeps struct {
|
|
fx.In
|
|
MetricsHandler metrics.Handler
|
|
Logger log.Logger
|
|
ClientFactory sdk.ClientFactory
|
|
MatchingClient resource.MatchingClient
|
|
HistoryClient resource.HistoryClient
|
|
WorkerDeploymentClient Client
|
|
WorkerControllerInstanceClient wciclient.Client
|
|
}
|
|
|
|
fxResult struct {
|
|
fx.Out
|
|
Component workercommon.PerNSWorkerComponent `group:"perNamespaceWorkerComponent"`
|
|
}
|
|
)
|
|
|
|
var ClientModule = fx.Options(
|
|
wciclient.Module,
|
|
fx.Provide(ClientProvider),
|
|
)
|
|
|
|
var Module = fx.Options(
|
|
ClientModule,
|
|
fx.Provide(NewResult),
|
|
)
|
|
|
|
func ClientProvider(
|
|
lc fx.Lifecycle,
|
|
logger log.Logger,
|
|
historyClient resource.HistoryClient,
|
|
matchingClient resource.MatchingClient,
|
|
visibilityManager manager.VisibilityManager,
|
|
workerControllerInstanceClient wciclient.Client,
|
|
dc *dynamicconfig.Collection,
|
|
testHooks testhooks.TestHooks,
|
|
metricsHandler metrics.Handler,
|
|
) Client {
|
|
highestRevSignaledToVersionWf := cache.New(dynamicconfig.ReactivationSignalDedupCacheMaxSize.Get(dc)(), nil)
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(context.Context) error {
|
|
highestRevSignaledToVersionWf.Stop()
|
|
return nil
|
|
},
|
|
})
|
|
return &ClientImpl{
|
|
logger: logger,
|
|
historyClient: historyClient,
|
|
visibilityManager: visibilityManager,
|
|
matchingClient: matchingClient,
|
|
workerControllerInstanceClient: workerControllerInstanceClient,
|
|
maxIDLengthLimit: dynamicconfig.MaxIDLengthLimit.Get(dc),
|
|
visibilityMaxPageSize: dynamicconfig.FrontendVisibilityMaxPageSize.Get(dc),
|
|
maxTaskQueuesInDeploymentVersion: dynamicconfig.MatchingMaxTaskQueuesInDeploymentVersion.Get(dc),
|
|
maxDeployments: dynamicconfig.MatchingMaxDeployments.Get(dc),
|
|
testHooks: testHooks,
|
|
metricsHandler: metricsHandler,
|
|
highestRevSignaledToVersionWf: highestRevSignaledToVersionWf,
|
|
}
|
|
}
|
|
|
|
func NewResult(
|
|
dc *dynamicconfig.Collection,
|
|
params activityDeps,
|
|
) fxResult {
|
|
return fxResult{
|
|
Component: &workerComponent{
|
|
activityDeps: params,
|
|
dynamicConfig: dc,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (s *workerComponent) DedicatedWorkerOptions(ns *namespace.Namespace) *workercommon.PerNSDedicatedWorkerOptions {
|
|
return &workercommon.PerNSDedicatedWorkerOptions{
|
|
Enabled: true,
|
|
}
|
|
}
|
|
|
|
func (s *workerComponent) Register(registry sdkworker.Registry, ns *namespace.Namespace, details workercommon.RegistrationDetails) func() {
|
|
workflowVersionGetter := func() DeploymentWorkflowVersion {
|
|
val := DeploymentWorkflowVersion(dynamicconfig.MatchingDeploymentWorkflowVersion.Get(s.dynamicConfig)(ns.Name().String()))
|
|
return val
|
|
}
|
|
|
|
versionWorkflow := func(ctx workflow.Context, args *deploymentspb.WorkerDeploymentVersionWorkflowArgs) error {
|
|
refreshIntervalGetter := func() time.Duration {
|
|
return dynamicconfig.VersionDrainageStatusRefreshInterval.Get(s.dynamicConfig)(ns.Name().String())
|
|
}
|
|
visibilityGracePeriodGetter := func() time.Duration {
|
|
return dynamicconfig.VersionDrainageStatusVisibilityGracePeriod.Get(s.dynamicConfig)(ns.Name().String())
|
|
}
|
|
return VersionWorkflow(ctx, workflowVersionGetter, refreshIntervalGetter, visibilityGracePeriodGetter, args)
|
|
}
|
|
registry.RegisterWorkflowWithOptions(versionWorkflow, workflow.RegisterOptions{Name: WorkerDeploymentVersionWorkflowType})
|
|
|
|
deploymentWorkflow := func(ctx workflow.Context, args *deploymentspb.WorkerDeploymentWorkflowArgs) error {
|
|
maxVersionsGetter := func() int {
|
|
return dynamicconfig.MatchingMaxVersionsInDeployment.Get(s.dynamicConfig)(ns.Name().String())
|
|
}
|
|
return Workflow(ctx, workflowVersionGetter, maxVersionsGetter, args)
|
|
}
|
|
registry.RegisterWorkflowWithOptions(deploymentWorkflow, workflow.RegisterOptions{Name: WorkerDeploymentWorkflowType})
|
|
|
|
versionActivities := &VersionActivities{
|
|
activityDeps: s.activityDeps,
|
|
namespace: ns,
|
|
}
|
|
registry.RegisterActivity(versionActivities)
|
|
|
|
activities := &Activities{
|
|
activityDeps: s.activityDeps,
|
|
namespace: ns,
|
|
}
|
|
registry.RegisterActivity(activities)
|
|
return nil
|
|
}
|