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).
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package queues
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/tasks/common/headers"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/namespace"
|
|
)
|
|
|
|
type (
|
|
activeStandbyExecutor struct {
|
|
currentClusterName string
|
|
registry namespace.Registry
|
|
activeExecutor Executor
|
|
standbyExecutor Executor
|
|
logger log.Logger
|
|
}
|
|
)
|
|
|
|
func NewActiveStandbyExecutor(
|
|
currentClusterName string,
|
|
registry namespace.Registry,
|
|
activeExecutor Executor,
|
|
standbyExecutor Executor,
|
|
logger log.Logger,
|
|
) Executor {
|
|
return &activeStandbyExecutor{
|
|
currentClusterName: currentClusterName,
|
|
registry: registry,
|
|
activeExecutor: activeExecutor,
|
|
standbyExecutor: standbyExecutor,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (e *activeStandbyExecutor) Execute(
|
|
ctx context.Context,
|
|
executable Executable,
|
|
) ExecuteResponse {
|
|
if e.isActiveTask(executable) {
|
|
return e.activeExecutor.Execute(ctx, executable)
|
|
}
|
|
|
|
// for standby tasks, use preemptable callerType to avoid impacting active traffic
|
|
return e.standbyExecutor.Execute(
|
|
headers.SetCallerType(ctx, headers.CallerTypePreemptable),
|
|
executable,
|
|
)
|
|
}
|
|
|
|
func (e *activeStandbyExecutor) isActiveTask(
|
|
executable Executable,
|
|
) bool {
|
|
// Following is the existing task allocator logic for verifying active task
|
|
|
|
namespaceID := executable.GetNamespaceID()
|
|
entry, err := e.registry.GetNamespaceByID(namespace.ID(namespaceID))
|
|
if err != nil {
|
|
e.logger.Warn("Unable to find namespace, process task as active.", tag.WorkflowNamespaceID(namespaceID), tag.Value(executable.GetTask()))
|
|
return true
|
|
}
|
|
|
|
if !entry.ActiveInCluster(e.currentClusterName) {
|
|
e.logger.Debug("Process task as standby.", tag.WorkflowNamespaceID(namespaceID), tag.Value(executable.GetTask()))
|
|
return false
|
|
}
|
|
|
|
e.logger.Debug("Process task as active.", tag.WorkflowNamespaceID(namespaceID), tag.Value(executable.GetTask()))
|
|
return true
|
|
}
|