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).
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package configs
|
|
|
|
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 (
|
|
CallerTypeToPriority = map[string]int{
|
|
headers.CallerTypeOperator: OperatorPriority,
|
|
headers.CallerTypeAPI: 1,
|
|
headers.CallerTypeBackgroundHigh: 2,
|
|
headers.CallerTypeBackgroundLow: 3,
|
|
headers.CallerTypePreemptable: 4,
|
|
}
|
|
|
|
APIPrioritiesOrdered = []int{OperatorPriority, 1, 2, 3, 4}
|
|
)
|
|
|
|
func NewPriorityRateLimiter(
|
|
rateFn quotas.RateFn,
|
|
operatorRPSRatio dynamicconfig.FloatPropertyFn,
|
|
) quotas.RequestRateLimiter {
|
|
rateLimiters := make(map[int]quotas.RequestRateLimiter)
|
|
for priority := range APIPrioritiesOrdered {
|
|
if priority == OperatorPriority {
|
|
rateLimiters[priority] = quotas.NewRequestRateLimiterAdapter(quotas.NewDefaultIncomingRateLimiter(operatorRateFn(rateFn, operatorRPSRatio)))
|
|
} else {
|
|
rateLimiters[priority] = quotas.NewRequestRateLimiterAdapter(quotas.NewDefaultIncomingRateLimiter(rateFn))
|
|
}
|
|
}
|
|
return quotas.NewPriorityRateLimiter(func(req quotas.Request) int {
|
|
if priority, ok := CallerTypeToPriority[req.CallerType]; ok {
|
|
return priority
|
|
}
|
|
// unknown caller type, default to api to be consistent with existing behavior
|
|
return CallerTypeToPriority[headers.CallerTypeAPI]
|
|
}, rateLimiters)
|
|
}
|
|
|
|
func operatorRateFn(
|
|
rateFn quotas.RateFn,
|
|
operatorRPSRatio dynamicconfig.FloatPropertyFn,
|
|
) quotas.RateFn {
|
|
return func() float64 {
|
|
return operatorRPSRatio() * rateFn()
|
|
}
|
|
}
|