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.0 KiB
Go
55 lines
1.0 KiB
Go
package vclock
|
|
|
|
import (
|
|
"go.temporal.io/api/serviceerror"
|
|
clockspb "github.com/hanzoai/tasks/api/clock/v1"
|
|
)
|
|
|
|
func NewVectorClock(
|
|
clusterID int64,
|
|
shardID int32,
|
|
clock int64,
|
|
) *clockspb.VectorClock {
|
|
return &clockspb.VectorClock{
|
|
ClusterId: clusterID,
|
|
ShardId: shardID,
|
|
Clock: clock,
|
|
}
|
|
}
|
|
|
|
func Comparable(
|
|
clock1 *clockspb.VectorClock,
|
|
clock2 *clockspb.VectorClock,
|
|
) bool {
|
|
if clock1 == nil || clock2 == nil {
|
|
return false
|
|
}
|
|
return clock1.GetClusterId() == clock2.GetClusterId() &&
|
|
clock1.GetShardId() == clock2.GetShardId()
|
|
}
|
|
|
|
func Compare(
|
|
clock1 *clockspb.VectorClock,
|
|
clock2 *clockspb.VectorClock,
|
|
) (int, error) {
|
|
if !Comparable(clock1, clock2) {
|
|
return 0, serviceerror.NewInternalf(
|
|
"Encountered shard ID mismatch: %v:%v vs %v:%v",
|
|
clock1.GetClusterId(),
|
|
clock1.GetShardId(),
|
|
clock2.GetClusterId(),
|
|
clock2.GetShardId(),
|
|
)
|
|
}
|
|
|
|
vClock1 := clock1.GetClock()
|
|
vClock2 := clock2.GetClock()
|
|
if vClock1 < vClock2 {
|
|
return -1, nil
|
|
} else if vClock1 > vClock2 {
|
|
return 1, nil
|
|
} else {
|
|
return 0, nil
|
|
}
|
|
}
|