mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## What changed? Reverting dropping tasks when feature flag disabled -> returning error Interface change for active or not based on business id ## Why? regression ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package queues
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.temporal.io/server/common/headers"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/log/tag"
|
|
"go.temporal.io/server/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.ActiveClusterName(namespace.RoutingKey{ID: executable.GetWorkflowID()}) != 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
|
|
}
|