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).
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package visibility
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/common/dynamicconfig"
|
|
"github.com/hanzoai/tasks/common/headers"
|
|
"github.com/hanzoai/tasks/common/quotas"
|
|
)
|
|
|
|
const (
|
|
// OperatorPriority is used to give precedence to calls coming from web UI or tctl
|
|
OperatorPriority = 0
|
|
)
|
|
|
|
var (
|
|
PrioritiesOrdered = []int{OperatorPriority, 1}
|
|
)
|
|
|
|
func newPriorityRateLimiter(
|
|
maxQPS dynamicconfig.IntPropertyFn,
|
|
operatorRPSRatio dynamicconfig.FloatPropertyFn,
|
|
) quotas.RequestRateLimiter {
|
|
rateLimiters := make(map[int]quotas.RequestRateLimiter)
|
|
for priority := range PrioritiesOrdered {
|
|
if priority == OperatorPriority {
|
|
rateLimiters[priority] = quotas.NewRequestRateLimiterAdapter(quotas.NewDefaultOutgoingRateLimiter(operatorRateFn(maxQPS, operatorRPSRatio)))
|
|
} else {
|
|
rateLimiters[priority] = quotas.NewRequestRateLimiterAdapter(quotas.NewDefaultOutgoingRateLimiter(rateFn(maxQPS)))
|
|
}
|
|
}
|
|
return quotas.NewPriorityRateLimiter(func(req quotas.Request) int {
|
|
if req.CallerType == headers.CallerTypeOperator {
|
|
return OperatorPriority
|
|
}
|
|
// default to lowest priority
|
|
return PrioritiesOrdered[len(PrioritiesOrdered)-1]
|
|
}, rateLimiters)
|
|
}
|
|
|
|
func rateFn(maxQPS dynamicconfig.IntPropertyFn) quotas.RateFn {
|
|
return func() float64 {
|
|
return float64(maxQPS())
|
|
}
|
|
}
|
|
|
|
func operatorRateFn(maxQPS dynamicconfig.IntPropertyFn, operatorRPSRatio dynamicconfig.FloatPropertyFn) quotas.RateFn {
|
|
return func() float64 {
|
|
return float64(maxQPS()) * operatorRPSRatio()
|
|
}
|
|
}
|