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).
109 lines
2.9 KiB
Go
109 lines
2.9 KiB
Go
//nolint:staticcheck
|
|
package worker_versioning
|
|
|
|
import (
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"github.com/hanzoai/tasks/common/cache"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
)
|
|
|
|
// VersionMembershipCache is used to cache results of Matching's CheckTaskQueueVersionMembership
|
|
// calls (used internally by the worker versioning pinned override validation).
|
|
//
|
|
// Implementations are expected to be safe for concurrent use.
|
|
type (
|
|
VersionMembershipCache interface {
|
|
// Get returns (isMember, ok). ok=false means there was no cached value.
|
|
Get(
|
|
namespaceID string,
|
|
taskQueue string,
|
|
taskQueueType enumspb.TaskQueueType,
|
|
deploymentName string,
|
|
buildID string,
|
|
) (isMember bool, ok bool)
|
|
|
|
Put(
|
|
namespaceID string,
|
|
taskQueue string,
|
|
taskQueueType enumspb.TaskQueueType,
|
|
deploymentName string,
|
|
buildID string,
|
|
isMember bool,
|
|
)
|
|
}
|
|
|
|
versionMembershipCacheKey struct {
|
|
namespaceID string
|
|
taskQueue string
|
|
taskQueueType enumspb.TaskQueueType
|
|
deploymentName string
|
|
buildID string
|
|
}
|
|
|
|
VersionMembershipCacheImpl struct {
|
|
cache.Cache
|
|
metricsHandler metrics.Handler
|
|
}
|
|
)
|
|
|
|
// NewVersionMembershipCache wraps the provided cache with a typed API and metrics.
|
|
func NewVersionMembershipCache(c cache.Cache, metricsHandler metrics.Handler) VersionMembershipCache {
|
|
h := metricsHandler.WithTags(metrics.CacheTypeTag(metrics.VersionMembershipCacheTypeTagValue))
|
|
return &VersionMembershipCacheImpl{
|
|
Cache: c,
|
|
metricsHandler: h,
|
|
}
|
|
}
|
|
|
|
func (c *VersionMembershipCacheImpl) Get(
|
|
namespaceID string,
|
|
taskQueue string,
|
|
taskQueueType enumspb.TaskQueueType,
|
|
deploymentName string,
|
|
buildID string,
|
|
) (isMember bool, ok bool) {
|
|
handler := c.metricsHandler.WithTags(metrics.OperationTag(metrics.VersionMembershipCacheGetScope), metrics.NamespaceIDTag(namespaceID))
|
|
metrics.CacheRequests.With(handler).Record(1)
|
|
|
|
key := versionMembershipCacheKey{
|
|
namespaceID: namespaceID,
|
|
taskQueue: taskQueue,
|
|
taskQueueType: taskQueueType,
|
|
deploymentName: deploymentName,
|
|
buildID: buildID,
|
|
}
|
|
v := c.Cache.Get(key)
|
|
if v == nil {
|
|
metrics.CacheMissCounter.With(handler).Record(1)
|
|
return false, false
|
|
}
|
|
isMember, ok = v.(bool)
|
|
if !ok {
|
|
// Unexpected type: treat as miss to avoid false positives.
|
|
metrics.CacheMissCounter.With(handler).Record(1)
|
|
return false, false
|
|
}
|
|
return isMember, true
|
|
}
|
|
|
|
func (c *VersionMembershipCacheImpl) Put(
|
|
namespaceID string,
|
|
taskQueue string,
|
|
taskQueueType enumspb.TaskQueueType,
|
|
deploymentName string,
|
|
buildID string,
|
|
isMember bool,
|
|
) {
|
|
handler := c.metricsHandler.WithTags(metrics.OperationTag(metrics.VersionMembershipCachePutScope), metrics.NamespaceIDTag(namespaceID))
|
|
metrics.CacheRequests.With(handler).Record(1)
|
|
|
|
key := versionMembershipCacheKey{
|
|
namespaceID: namespaceID,
|
|
taskQueue: taskQueue,
|
|
taskQueueType: taskQueueType,
|
|
deploymentName: deploymentName,
|
|
buildID: buildID,
|
|
}
|
|
c.Cache.Put(key, isMember)
|
|
}
|