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).
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package configs
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/tasks"
|
|
)
|
|
|
|
var (
|
|
DefaultPriorityWeight = 1
|
|
|
|
DefaultActiveTaskPriorityWeight = map[tasks.Priority]int{
|
|
tasks.PriorityHigh: 10,
|
|
tasks.PriorityLow: 9,
|
|
tasks.PriorityPreemptable: 1,
|
|
}
|
|
|
|
DefaultStandbyTaskPriorityWeight = map[tasks.Priority]int{
|
|
// we basically treat standby tasks as low priority tasks
|
|
tasks.PriorityHigh: 1,
|
|
tasks.PriorityLow: 1,
|
|
tasks.PriorityPreemptable: 1,
|
|
}
|
|
)
|
|
|
|
func ConvertWeightsToDynamicConfigValue(
|
|
weights map[tasks.Priority]int,
|
|
) map[string]any {
|
|
weightsForDC := make(map[string]any)
|
|
for priority, weight := range weights {
|
|
weightsForDC[priority.String()] = weight
|
|
}
|
|
return weightsForDC
|
|
}
|
|
|
|
func ConvertDynamicConfigValueToWeights(
|
|
weightsFromDC map[string]any,
|
|
logger log.Logger,
|
|
) map[tasks.Priority]int {
|
|
weights := make(map[tasks.Priority]int)
|
|
for key, value := range weightsFromDC {
|
|
priority, ok := tasks.PriorityValue[key]
|
|
if !ok {
|
|
logger.Error("Unknown key for task priority name, fallback to default weights", tag.Key(key), tag.Value(value))
|
|
return DefaultActiveTaskPriorityWeight
|
|
}
|
|
|
|
var intValue int
|
|
switch value := value.(type) {
|
|
case float64:
|
|
intValue = int(value)
|
|
case int:
|
|
intValue = value
|
|
case int32:
|
|
intValue = int(value)
|
|
case int64:
|
|
intValue = int(value)
|
|
default:
|
|
logger.Error("Unknown type for task priority weight, fallback to default weights", tag.Key(key), tag.Value(value))
|
|
return DefaultActiveTaskPriorityWeight
|
|
}
|
|
weights[priority] = intValue
|
|
}
|
|
return weights
|
|
}
|