Files
tasks/service/history/replication/sequential_queue.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

89 lines
1.9 KiB
Go

package replication
import (
"sync"
"github.com/dgryski/go-farm"
"github.com/hanzoai/tasks/common/collection"
"github.com/hanzoai/tasks/common/definition"
ctasks "github.com/hanzoai/tasks/common/tasks"
)
type (
SequentialTaskQueue struct {
id any
sync.Mutex
taskQueue collection.Queue[TrackableExecutableTask]
}
)
func NewSequentialTaskQueue(task TrackableExecutableTask) ctasks.SequentialTaskQueue[TrackableExecutableTask] {
return &SequentialTaskQueue{
id: task.QueueID(),
taskQueue: collection.NewPriorityQueue[TrackableExecutableTask](
SequentialTaskQueueCompareLess,
),
}
}
func NewSequentialTaskQueueWithID(id any) ctasks.SequentialTaskQueue[TrackableExecutableTask] {
return &SequentialTaskQueue{
id: id,
taskQueue: collection.NewPriorityQueue[TrackableExecutableTask](
SequentialTaskQueueCompareLess,
),
}
}
func (q *SequentialTaskQueue) ID() any {
return q.id
}
func (q *SequentialTaskQueue) Peek() TrackableExecutableTask {
q.Lock()
defer q.Unlock()
return q.taskQueue.Peek()
}
func (q *SequentialTaskQueue) Add(task TrackableExecutableTask) {
q.Lock()
defer q.Unlock()
q.taskQueue.Add(task)
}
func (q *SequentialTaskQueue) Remove() TrackableExecutableTask {
q.Lock()
defer q.Unlock()
return q.taskQueue.Remove().(TrackableExecutableTask)
}
func (q *SequentialTaskQueue) IsEmpty() bool {
q.Lock()
defer q.Unlock()
return q.taskQueue.IsEmpty()
}
func (q *SequentialTaskQueue) Len() int {
q.Lock()
defer q.Unlock()
return q.taskQueue.Len()
}
func SequentialTaskQueueCompareLess(this TrackableExecutableTask, that TrackableExecutableTask) bool {
return this.TaskID() < that.TaskID()
}
func WorkflowKeyHashFn(
item any,
) uint32 {
workflowKey, ok := item.(definition.WorkflowKey)
if !ok {
return 0
}
idBytes := []byte(workflowKey.NamespaceID + "_" + workflowKey.WorkflowID + "_" + workflowKey.RunID)
return farm.Fingerprint32(idBytes)
}