mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? This PR extracts the “should this cluster process an incoming namespace replication task?” decision into a new `NamespaceReplicationAdmitter` interface. Allows custom override that decides whether the current cluster should admit an incoming namespace replication task for a namespace that does not yet exist locally. > Note: The default behavior is unchanged. ## Why? Allow integrate with custom `admitter` to override the replication logic. ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s)
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package nsreplication
|
|
|
|
import (
|
|
"context"
|
|
|
|
replicationpb "go.temporal.io/api/replication/v1"
|
|
replicationspb "go.temporal.io/server/api/replication/v1"
|
|
)
|
|
|
|
// NamespaceReplicationAdmitter decides whether to process a namespace
|
|
// replication task when the namespace does not yet exist locally.
|
|
type NamespaceReplicationAdmitter interface {
|
|
Admit(ctx context.Context, currentCluster string, task *replicationspb.NamespaceTaskAttributes) bool
|
|
}
|
|
|
|
// DefaultAdmitter is the default implementation: admit the task iff the
|
|
// current cluster is listed in task.ReplicationConfig.Clusters.
|
|
type DefaultAdmitter struct{}
|
|
|
|
// NewDefaultAdmitter creates the default NamespaceReplicationAdmitter.
|
|
func NewDefaultAdmitter() NamespaceReplicationAdmitter {
|
|
return &DefaultAdmitter{}
|
|
}
|
|
|
|
// Admit returns true iff currentCluster appears in the task's replication
|
|
// config cluster list.
|
|
func (*DefaultAdmitter) Admit(
|
|
_ context.Context,
|
|
currentCluster string,
|
|
task *replicationspb.NamespaceTaskAttributes,
|
|
) bool {
|
|
return checkClusterIncludedInReplicationConfig(currentCluster, task.GetReplicationConfig().GetClusters())
|
|
}
|
|
|
|
func checkClusterIncludedInReplicationConfig(clusterName string, repCfg []*replicationpb.ClusterReplicationConfig) bool {
|
|
for _, cluster := range repCfg {
|
|
if clusterName == cluster.GetClusterName() {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|