Files
tasks/service/worker/workerdeployment/fx.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

141 lines
4.7 KiB
Go

package workerdeployment
import (
"time"
sdkworker "go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
deploymentspb "github.com/hanzoai/tasks/api/deployment/v1"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/namespace"
"github.com/hanzoai/tasks/common/persistence/visibility/manager"
"github.com/hanzoai/tasks/common/resource"
"github.com/hanzoai/tasks/common/sdk"
"github.com/hanzoai/tasks/common/testing/testhooks"
workercommon "github.com/hanzoai/tasks/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
}
fxResult struct {
fx.Out
Component workercommon.PerNSWorkerComponent `group:"perNamespaceWorkerComponent"`
}
)
var Module = fx.Options(
fx.Provide(NewResult),
fx.Provide(ClientProvider),
)
func ClientProvider(
logger log.Logger,
historyClient resource.HistoryClient,
matchingClient resource.MatchingClient,
visibilityManager manager.VisibilityManager,
dc *dynamicconfig.Collection,
testHooks testhooks.TestHooks,
metricsHandler metrics.Handler,
) Client {
return &ClientImpl{
logger: logger,
historyClient: historyClient,
visibilityManager: visibilityManager,
matchingClient: matchingClient,
maxIDLengthLimit: dynamicconfig.MaxIDLengthLimit.Get(dc),
visibilityMaxPageSize: dynamicconfig.FrontendVisibilityMaxPageSize.Get(dc),
maxTaskQueuesInDeploymentVersion: dynamicconfig.MatchingMaxTaskQueuesInDeploymentVersion.Get(dc),
maxDeployments: dynamicconfig.MatchingMaxDeployments.Get(dc),
testHooks: testHooks,
metricsHandler: metricsHandler,
}
}
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
}