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).
90 lines
1.8 KiB
Go
90 lines
1.8 KiB
Go
package queues
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/tasks/service/history/tasks"
|
|
)
|
|
|
|
type (
|
|
Range struct {
|
|
InclusiveMin tasks.Key
|
|
ExclusiveMax tasks.Key
|
|
}
|
|
)
|
|
|
|
func NewRange(
|
|
inclusiveMin tasks.Key,
|
|
exclusiveMax tasks.Key,
|
|
) Range {
|
|
if inclusiveMin.CompareTo(exclusiveMax) > 0 {
|
|
panic(fmt.Sprintf("invalid task range, min %v is larger than max %v", inclusiveMin, exclusiveMax))
|
|
}
|
|
|
|
return Range{
|
|
InclusiveMin: inclusiveMin,
|
|
ExclusiveMax: exclusiveMax,
|
|
}
|
|
}
|
|
|
|
func (r *Range) IsEmpty() bool {
|
|
return r.InclusiveMin.CompareTo(r.ExclusiveMax) == 0
|
|
}
|
|
|
|
func (r *Range) ContainsKey(
|
|
key tasks.Key,
|
|
) bool {
|
|
return key.CompareTo(r.InclusiveMin) >= 0 &&
|
|
key.CompareTo(r.ExclusiveMax) < 0
|
|
}
|
|
|
|
func (r *Range) ContainsRange(
|
|
input Range,
|
|
) bool {
|
|
return r.InclusiveMin.CompareTo(input.InclusiveMin) <= 0 &&
|
|
r.ExclusiveMax.CompareTo(input.ExclusiveMax) >= 0
|
|
}
|
|
|
|
func (r *Range) CanSplit(
|
|
key tasks.Key,
|
|
) bool {
|
|
return r.ContainsKey(key) || r.ExclusiveMax.CompareTo(key) == 0
|
|
}
|
|
|
|
func (r *Range) Split(
|
|
key tasks.Key,
|
|
) (left Range, right Range) {
|
|
if !r.CanSplit(key) {
|
|
panic(fmt.Sprintf("Unable to split range %v at %v", r, key))
|
|
}
|
|
|
|
return NewRange(r.InclusiveMin, key), NewRange(key, r.ExclusiveMax)
|
|
}
|
|
|
|
func (r *Range) CanMerge(
|
|
input Range,
|
|
) bool {
|
|
return r.InclusiveMin.CompareTo(input.ExclusiveMax) <= 0 &&
|
|
r.ExclusiveMax.CompareTo(input.InclusiveMin) >= 0
|
|
}
|
|
|
|
func (r *Range) Merge(
|
|
input Range,
|
|
) Range {
|
|
if !r.CanMerge(input) {
|
|
panic(fmt.Sprintf("Unable to merge range %v with incoming range %v", r, input))
|
|
}
|
|
|
|
return NewRange(
|
|
tasks.MinKey(r.InclusiveMin, input.InclusiveMin),
|
|
tasks.MaxKey(r.ExclusiveMax, input.ExclusiveMax),
|
|
)
|
|
}
|
|
|
|
func (r *Range) Equals(
|
|
input Range,
|
|
) bool {
|
|
return r.InclusiveMin.CompareTo(input.InclusiveMin) == 0 &&
|
|
r.ExclusiveMax.CompareTo(input.ExclusiveMax) == 0
|
|
}
|