mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
209 lines
6.4 KiB
Go
209 lines
6.4 KiB
Go
package history
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/client"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
"github.com/hanzoai/tasks/common/persistence/visibility/manager"
|
|
"github.com/hanzoai/tasks/common/resource"
|
|
ctasks "github.com/hanzoai/tasks/common/tasks"
|
|
"github.com/hanzoai/tasks/common/telemetry"
|
|
"github.com/hanzoai/tasks/service/history/deletemanager"
|
|
historyi "github.com/hanzoai/tasks/service/history/interfaces"
|
|
"github.com/hanzoai/tasks/service/history/queues"
|
|
"github.com/hanzoai/tasks/service/history/tasks"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
const (
|
|
timerQueuePersistenceMaxRPSRatio = 0.3
|
|
)
|
|
|
|
type (
|
|
timerQueueFactoryParams struct {
|
|
fx.In
|
|
|
|
QueueFactoryBaseParams
|
|
ClientBean client.Bean
|
|
MatchingRawClient resource.MatchingRawClient
|
|
VisibilityManager manager.VisibilityManager
|
|
}
|
|
|
|
timerQueueFactory struct {
|
|
timerQueueFactoryParams
|
|
QueueFactoryBase
|
|
}
|
|
)
|
|
|
|
func NewTimerQueueFactory(
|
|
params timerQueueFactoryParams,
|
|
) QueueFactory {
|
|
return &timerQueueFactory{
|
|
timerQueueFactoryParams: params,
|
|
QueueFactoryBase: QueueFactoryBase{
|
|
HostScheduler: queues.NewScheduler(
|
|
params.ClusterMetadata.GetCurrentClusterName(),
|
|
queues.SchedulerOptions{
|
|
WorkerCount: params.Config.TimerProcessorSchedulerWorkerCount,
|
|
ActiveNamespaceWeights: params.Config.TimerProcessorSchedulerActiveRoundRobinWeights,
|
|
StandbyNamespaceWeights: params.Config.TimerProcessorSchedulerStandbyRoundRobinWeights,
|
|
InactiveNamespaceDeletionDelay: params.Config.TaskSchedulerInactiveChannelDeletionDelay,
|
|
ExecutionAwareSchedulerOptions: ctasks.ExecutionAwareSchedulerOptions{
|
|
Enabled: params.Config.TaskSchedulerEnableExecutionQueueScheduler,
|
|
MaxQueues: params.Config.TaskSchedulerExecutionQueueSchedulerMaxQueues,
|
|
QueueTTL: params.Config.TaskSchedulerExecutionQueueSchedulerQueueTTL,
|
|
QueueConcurrency: params.Config.TaskSchedulerExecutionQueueSchedulerQueueConcurrency,
|
|
},
|
|
},
|
|
params.NamespaceRegistry,
|
|
params.Logger,
|
|
params.MetricsHandler,
|
|
params.TimeSource,
|
|
),
|
|
HostPriorityAssigner: queues.NewPriorityAssigner(
|
|
params.NamespaceRegistry,
|
|
params.ClusterMetadata.GetCurrentClusterName(),
|
|
),
|
|
HostReaderRateLimiter: queues.NewReaderPriorityRateLimiter(
|
|
NewHostRateLimiterRateFn(
|
|
params.Config.TimerProcessorMaxPollHostRPS,
|
|
params.Config.PersistenceMaxQPS,
|
|
timerQueuePersistenceMaxRPSRatio,
|
|
),
|
|
int64(params.Config.TimerQueueMaxReaderCount()),
|
|
),
|
|
Tracer: params.TracerProvider.Tracer(telemetry.ComponentQueueTimer),
|
|
},
|
|
}
|
|
}
|
|
|
|
func (f *timerQueueFactory) CreateQueue(
|
|
shardContext historyi.ShardContext,
|
|
) queues.Queue {
|
|
logger := log.With(shardContext.GetLogger(), tag.ComponentTimerQueue)
|
|
metricsHandler := f.MetricsHandler.WithTags(metrics.OperationTag(metrics.OperationTimerQueueProcessorScope))
|
|
|
|
currentClusterName := f.ClusterMetadata.GetCurrentClusterName()
|
|
workflowDeleteManager := deletemanager.NewDeleteManager(
|
|
shardContext,
|
|
f.WorkflowCache,
|
|
f.Config,
|
|
shardContext.GetTimeSource(),
|
|
f.VisibilityManager,
|
|
)
|
|
|
|
shardScheduler := queues.NewRateLimitedScheduler(
|
|
f.HostScheduler,
|
|
queues.RateLimitedSchedulerOptions{
|
|
Enabled: f.Config.TaskSchedulerEnableRateLimiter,
|
|
EnableShadowMode: f.Config.TaskSchedulerEnableRateLimiterShadowMode,
|
|
StartupDelay: f.Config.TaskSchedulerRateLimiterStartupDelay,
|
|
},
|
|
currentClusterName,
|
|
f.NamespaceRegistry,
|
|
f.SchedulerRateLimiter,
|
|
f.TimeSource,
|
|
f.ChasmRegistry,
|
|
logger,
|
|
metricsHandler,
|
|
)
|
|
|
|
rescheduler := queues.NewRescheduler(
|
|
shardScheduler,
|
|
shardContext.GetTimeSource(),
|
|
logger,
|
|
metricsHandler,
|
|
)
|
|
|
|
activeExecutor := newTimerQueueActiveTaskExecutor(
|
|
shardContext,
|
|
f.WorkflowCache,
|
|
workflowDeleteManager,
|
|
logger,
|
|
f.MetricsHandler,
|
|
f.Config,
|
|
f.MatchingRawClient,
|
|
f.ChasmEngine,
|
|
)
|
|
|
|
standbyExecutor := newTimerQueueStandbyTaskExecutor(
|
|
shardContext,
|
|
f.WorkflowCache,
|
|
workflowDeleteManager,
|
|
f.MatchingRawClient,
|
|
f.ChasmEngine,
|
|
logger,
|
|
f.MetricsHandler,
|
|
// note: the cluster name is for calculating time for standby tasks,
|
|
// here we are basically using current cluster time
|
|
// this field will be deprecated soon, currently exists so that
|
|
// we have the option of revert to old behavior
|
|
currentClusterName,
|
|
f.Config,
|
|
f.ClientBean,
|
|
)
|
|
|
|
executor := queues.NewActiveStandbyExecutor(
|
|
currentClusterName,
|
|
f.NamespaceRegistry,
|
|
activeExecutor,
|
|
standbyExecutor,
|
|
logger,
|
|
)
|
|
if f.ExecutorWrapper != nil {
|
|
executor = f.ExecutorWrapper.Wrap(executor)
|
|
}
|
|
|
|
factory := queues.NewExecutableFactory(
|
|
executor,
|
|
shardScheduler,
|
|
rescheduler,
|
|
f.HostPriorityAssigner,
|
|
shardContext.GetTimeSource(),
|
|
shardContext.GetNamespaceRegistry(),
|
|
shardContext.GetClusterMetadata(),
|
|
f.ChasmRegistry,
|
|
queues.GetTaskTypeTagValue,
|
|
logger,
|
|
metricsHandler,
|
|
f.Tracer,
|
|
f.DLQWriter,
|
|
f.Config.TaskDLQEnabled,
|
|
f.Config.TaskDLQUnexpectedErrorAttempts,
|
|
f.Config.TaskDLQInternalErrors,
|
|
f.Config.TaskDLQErrorPattern,
|
|
)
|
|
return queues.NewScheduledQueue(
|
|
shardContext,
|
|
tasks.CategoryTimer,
|
|
shardScheduler,
|
|
rescheduler,
|
|
factory,
|
|
&queues.Options{
|
|
ReaderOptions: queues.ReaderOptions{
|
|
BatchSize: f.Config.TimerTaskBatchSize,
|
|
MaxPendingTasksCount: f.Config.QueuePendingTaskMaxCount,
|
|
PollBackoffInterval: f.Config.TimerProcessorPollBackoffInterval,
|
|
MaxPredicateSize: f.Config.QueueMaxPredicateSize,
|
|
},
|
|
MonitorOptions: queues.MonitorOptions{
|
|
PendingTasksCriticalCount: f.Config.QueuePendingTaskCriticalCount,
|
|
ReaderStuckCriticalAttempts: f.Config.QueueReaderStuckCriticalAttempts,
|
|
SliceCountCriticalThreshold: f.Config.QueueCriticalSlicesCount,
|
|
},
|
|
MaxPollRPS: f.Config.TimerProcessorMaxPollRPS,
|
|
MaxPollInterval: f.Config.TimerProcessorMaxPollInterval,
|
|
MaxPollIntervalJitterCoefficient: f.Config.TimerProcessorMaxPollIntervalJitterCoefficient,
|
|
CheckpointInterval: f.Config.TimerProcessorUpdateAckInterval,
|
|
CheckpointIntervalJitterCoefficient: f.Config.TimerProcessorUpdateAckIntervalJitterCoefficient,
|
|
MaxReaderCount: f.Config.TimerQueueMaxReaderCount,
|
|
MoveGroupTaskCountBase: f.Config.QueueMoveGroupTaskCountBase,
|
|
MoveGroupTaskCountMultiplier: f.Config.QueueMoveGroupTaskCountMultiplier,
|
|
},
|
|
f.HostReaderRateLimiter,
|
|
logger,
|
|
metricsHandler,
|
|
)
|
|
}
|