mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package queues
|
|
|
|
import (
|
|
"go.temporal.io/server/common/predicates"
|
|
"go.temporal.io/server/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{}
|
|
|
|
// NamespaceIDAndDestination is the key for grouping tasks by namespace ID and destination.
|
|
type NamespaceIDAndDestination struct {
|
|
NamespaceID string
|
|
Destination string
|
|
}
|
|
|
|
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{}
|