Files
tasks/service/worker/parentclosepolicy/processor.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

94 lines
3.4 KiB
Go

package parentclosepolicy
import (
"context"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
"github.com/hanzoai/tasks/client"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/headers"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
"github.com/hanzoai/tasks/common/membership"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/sdk"
)
type (
// Config defines the configuration for parent close policy worker
Config struct {
MaxConcurrentActivityExecutionSize dynamicconfig.IntPropertyFn
MaxConcurrentWorkflowTaskExecutionSize dynamicconfig.IntPropertyFn
MaxConcurrentActivityTaskPollers dynamicconfig.IntPropertyFn
MaxConcurrentWorkflowTaskPollers dynamicconfig.IntPropertyFn
NumParentClosePolicySystemWorkflows dynamicconfig.IntPropertyFn
}
// BootstrapParams contains the set of params needed to bootstrap the sub-system
BootstrapParams struct {
SdkClientFactory sdk.ClientFactory
// MetricsHandler is an instance of metrics object for emitting stats
MetricsHandler metrics.Handler
// Logger is the logger
Logger log.Logger
// Config contains the configuration for scanner
Config Config
// ClientBean is an instance of client.Bean for a collection of clients
ClientBean client.Bean
// CurrentCluster is the name of current cluster
CurrentCluster string
HostInfo membership.HostInfo
}
// Processor is the background sub-system that execute workflow for ParentClosePolicy
Processor struct {
sdkClientFactory sdk.ClientFactory
clientBean client.Bean
metricsHandler metrics.Handler
cfg Config
logger log.Logger
currentCluster string
hostInfo membership.HostInfo
}
)
// New returns a new instance as daemon
func New(params *BootstrapParams) *Processor {
return &Processor{
sdkClientFactory: params.SdkClientFactory,
metricsHandler: params.MetricsHandler.WithTags(metrics.OperationTag(metrics.ParentClosePolicyProcessorScope)),
cfg: params.Config,
logger: log.With(params.Logger, tag.ComponentBatcher),
clientBean: params.ClientBean,
currentCluster: params.CurrentCluster,
hostInfo: params.HostInfo,
}
}
// Start starts the scanner
func (s *Processor) Start() error {
svcClient := s.sdkClientFactory.GetSystemClient()
processorWorker := s.sdkClientFactory.NewWorker(svcClient, processorTaskQueueName, getWorkerOptions(s))
processorWorker.RegisterWorkflowWithOptions(ProcessorWorkflow, workflow.RegisterOptions{Name: processorWFTypeName})
processorWorker.RegisterActivityWithOptions(ProcessorActivity, activity.RegisterOptions{Name: processorActivityName})
return processorWorker.Start()
}
func getWorkerOptions(p *Processor) worker.Options {
ctx := context.WithValue(context.Background(), processorContextKey, p)
ctx = headers.SetCallerInfo(ctx, headers.SystemBackgroundHighCallerInfo)
return worker.Options{
MaxConcurrentActivityExecutionSize: p.cfg.MaxConcurrentActivityExecutionSize(),
MaxConcurrentWorkflowTaskExecutionSize: p.cfg.MaxConcurrentWorkflowTaskExecutionSize(),
MaxConcurrentActivityTaskPollers: p.cfg.MaxConcurrentActivityTaskPollers(),
MaxConcurrentWorkflowTaskPollers: p.cfg.MaxConcurrentWorkflowTaskPollers(),
BackgroundActivityContext: ctx,
Identity: "temporal-system@" + p.hostInfo.Identity(),
}
}