Files
tasks/service/worker/batcher/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

93 lines
2.9 KiB
Go

package batcher
import (
"go.temporal.io/api/workflowservice/v1"
sdkworker "go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
"github.com/hanzoai/tasks/api/adminservice/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/resource"
"github.com/hanzoai/tasks/common/sdk"
workercommon "github.com/hanzoai/tasks/service/worker/common"
"go.uber.org/fx"
)
const (
// BatchWFTypeName is the workflow type
BatchWFTypeName = "temporal-sys-batch-workflow"
BatchWFTypeProtobufName = "temporal-sys-batch-workflow-protobuf"
NamespaceDivision = "TemporalBatcher"
AdminNamespaceDivision = "TemporalAdminBatcher"
)
type (
workerComponent struct {
activityDeps activityDeps
dc *dynamicconfig.Collection
enabledFeature dynamicconfig.BoolPropertyFnWithNamespaceFilter
}
activityDeps struct {
fx.In
MetricsHandler metrics.Handler
Logger log.Logger
ClientFactory sdk.ClientFactory
FrontendClient workflowservice.WorkflowServiceClient
AdminClient adminservice.AdminServiceClient
HistoryClient resource.HistoryClient
}
fxResult struct {
fx.Out
Component workercommon.PerNSWorkerComponent `group:"perNamespaceWorkerComponent"`
}
)
var Module = fx.Options(
fx.Provide(NewResult),
)
func NewResult(
dc *dynamicconfig.Collection,
params activityDeps,
) fxResult {
return fxResult{
Component: &workerComponent{
activityDeps: params,
dc: dc,
enabledFeature: dynamicconfig.EnableBatcherNamespace.Get(dc),
},
}
}
func (s *workerComponent) DedicatedWorkerOptions(ns *namespace.Namespace) *workercommon.PerNSDedicatedWorkerOptions {
namespaceName := ns.Name().String()
enableFeature := s.enabledFeature(namespaceName)
return &workercommon.PerNSDedicatedWorkerOptions{
Enabled: enableFeature,
}
}
func (s *workerComponent) Register(registry sdkworker.Registry, ns *namespace.Namespace, _ workercommon.RegistrationDetails) func() {
// Register the batch workflow with both the proto-qualified and unqualified types.
// TODO(spkane31): Remove the proto-qualified type and call the unqualified type from the frontend after the 1.30 release.
registry.RegisterWorkflowWithOptions(BatchWorkflowProtobuf, workflow.RegisterOptions{Name: BatchWFTypeName})
// Newer version of the batch workflow which was rewritten to accept a proto struct as input.
registry.RegisterWorkflowWithOptions(BatchWorkflowProtobuf, workflow.RegisterOptions{Name: BatchWFTypeProtobufName})
registry.RegisterActivity(s.activities(ns.Name(), ns.ID()))
return nil
}
func (s *workerComponent) activities(name namespace.Name, id namespace.ID) *activities {
return &activities{
activityDeps: s.activityDeps,
namespace: name,
namespaceID: id,
rps: dynamicconfig.BatcherRPS.Get(s.dc),
concurrency: dynamicconfig.BatcherConcurrency.Get(s.dc),
}
}