mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +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`.
115 lines
2.3 KiB
Go
115 lines
2.3 KiB
Go
package queues
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"go.temporal.io/server/common/predicates"
|
|
"go.temporal.io/server/service/history/tasks"
|
|
)
|
|
|
|
type (
|
|
Scope struct {
|
|
Range Range
|
|
Predicate tasks.Predicate
|
|
}
|
|
)
|
|
|
|
func NewScope(
|
|
r Range,
|
|
predicate tasks.Predicate,
|
|
) Scope {
|
|
return Scope{
|
|
Range: r,
|
|
Predicate: predicate,
|
|
}
|
|
}
|
|
|
|
func (s *Scope) Contains(task tasks.Task) bool {
|
|
return s.Range.ContainsKey(task.GetKey()) &&
|
|
s.Predicate.Test(task)
|
|
}
|
|
|
|
func (s *Scope) CanSplitByRange(
|
|
key tasks.Key,
|
|
) bool {
|
|
return s.Range.CanSplit(key)
|
|
}
|
|
|
|
func (s *Scope) SplitByRange(
|
|
key tasks.Key,
|
|
) (left Scope, right Scope) {
|
|
if !s.CanSplitByRange(key) {
|
|
panic(fmt.Sprintf("Unable to split scope with range %v at %v", s.Range, key))
|
|
}
|
|
|
|
leftRange, rightRange := s.Range.Split(key)
|
|
return NewScope(leftRange, s.Predicate), NewScope(rightRange, s.Predicate)
|
|
}
|
|
|
|
func (s *Scope) SplitByPredicate(
|
|
predicate tasks.Predicate,
|
|
) (pass Scope, fail Scope) {
|
|
passScope := NewScope(
|
|
s.Range,
|
|
tasks.AndPredicates(s.Predicate, predicate),
|
|
)
|
|
failScope := NewScope(
|
|
s.Range,
|
|
predicates.And(
|
|
s.Predicate,
|
|
predicates.Not(predicate),
|
|
),
|
|
)
|
|
return passScope, failScope
|
|
}
|
|
|
|
func (s *Scope) CanMergeByRange(
|
|
incomingScope Scope,
|
|
) bool {
|
|
return s.Range.CanMerge(incomingScope.Range) &&
|
|
s.Predicate.Equals(incomingScope.Predicate)
|
|
}
|
|
|
|
func (s *Scope) MergeByRange(
|
|
incomingScope Scope,
|
|
) Scope {
|
|
if !s.CanMergeByRange(incomingScope) {
|
|
panic(fmt.Sprintf("Unable to merge scope with range %v with range %v by range", s.Range, incomingScope.Range))
|
|
}
|
|
|
|
return NewScope(s.Range.Merge(incomingScope.Range), s.Predicate)
|
|
}
|
|
|
|
func (s *Scope) CanMergeByPredicate(
|
|
incomingScope Scope,
|
|
) bool {
|
|
return s.Range.Equals(incomingScope.Range)
|
|
}
|
|
|
|
func (s *Scope) MergeByPredicate(
|
|
incomingScope Scope,
|
|
) Scope {
|
|
if !s.CanMergeByPredicate(incomingScope) {
|
|
panic(fmt.Sprintf("Unable to merge scope with range %v with range %v by predicate", s.Range, incomingScope.Range))
|
|
}
|
|
|
|
return NewScope(s.Range, tasks.OrPredicates(s.Predicate, incomingScope.Predicate))
|
|
}
|
|
|
|
func (s *Scope) IsEmpty() bool {
|
|
if s.Range.IsEmpty() {
|
|
return true
|
|
}
|
|
|
|
if _, ok := s.Predicate.(*predicates.EmptyImpl[tasks.Task]); ok {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (s *Scope) Equals(scope Scope) bool {
|
|
return s.Range.Equals(scope.Range) &&
|
|
s.Predicate.Equals(scope.Predicate)
|
|
}
|