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).
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package queues
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/common/predicates"
|
|
"github.com/hanzoai/tasks/service/history/tasks"
|
|
)
|
|
|
|
// Grouper groups tasks and constructs predicates for those groups.
|
|
type Grouper interface {
|
|
// Key returns the group key for a given task.
|
|
Key(task tasks.Task) (key any)
|
|
// Predicate constructs a prdicate from a slice of keys.
|
|
Predicate(keys []any) tasks.Predicate
|
|
}
|
|
|
|
type GrouperNamespaceID struct {
|
|
}
|
|
|
|
func (GrouperNamespaceID) Key(task tasks.Task) (key any) {
|
|
return task.GetNamespaceID()
|
|
}
|
|
|
|
func (GrouperNamespaceID) Predicate(keys []any) tasks.Predicate {
|
|
pendingNamespaceIDs := make([]string, len(keys))
|
|
for i, namespaceID := range keys {
|
|
// Assume predicate is only called with keys returned from GrouperNamespaceID.Key()
|
|
pendingNamespaceIDs[i] = namespaceID.(string)
|
|
}
|
|
return tasks.NewNamespacePredicate(pendingNamespaceIDs)
|
|
}
|
|
|
|
var _ Grouper = GrouperNamespaceID{}
|
|
|
|
type GrouperStateMachineNamespaceIDAndDestination struct {
|
|
}
|
|
|
|
func (g GrouperStateMachineNamespaceIDAndDestination) Key(task tasks.Task) (key any) {
|
|
return g.KeyTyped(task)
|
|
}
|
|
|
|
func (GrouperStateMachineNamespaceIDAndDestination) KeyTyped(task tasks.Task) (key tasks.TaskGroupNamespaceIDAndDestination) {
|
|
destGetter, ok := task.(tasks.HasDestination)
|
|
var dest string
|
|
if ok {
|
|
dest = destGetter.GetDestination()
|
|
}
|
|
smtGetter, ok := task.(tasks.HasStateMachineTaskType)
|
|
var smt string
|
|
if ok {
|
|
smt = smtGetter.StateMachineTaskType()
|
|
}
|
|
return tasks.TaskGroupNamespaceIDAndDestination{
|
|
TaskGroup: smt,
|
|
NamespaceID: task.GetNamespaceID(),
|
|
Destination: dest,
|
|
}
|
|
}
|
|
|
|
func (GrouperStateMachineNamespaceIDAndDestination) Predicate(keys []any) tasks.Predicate {
|
|
if len(keys) == 0 {
|
|
return predicates.Empty[tasks.Task]()
|
|
}
|
|
groups := make([]tasks.TaskGroupNamespaceIDAndDestination, len(keys))
|
|
for i, anyKey := range keys {
|
|
// Assume predicate is only called with keys returned from OutboundTaskGroupNamespaceIDAndDestination.Key()
|
|
key := anyKey.(tasks.TaskGroupNamespaceIDAndDestination)
|
|
groups[i] = key
|
|
}
|
|
return tasks.NewOutboundTaskPredicate(groups)
|
|
}
|
|
|
|
var _ Grouper = GrouperStateMachineNamespaceIDAndDestination{}
|