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).
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package queues
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/service/history/tasks"
|
|
)
|
|
|
|
var _ Action = (*actionReaderStuck)(nil)
|
|
|
|
type (
|
|
actionReaderStuck struct {
|
|
attributes *AlertAttributesReaderStuck
|
|
logger log.Logger
|
|
}
|
|
)
|
|
|
|
func newReaderStuckAction(
|
|
attributes *AlertAttributesReaderStuck,
|
|
logger log.Logger,
|
|
) *actionReaderStuck {
|
|
return &actionReaderStuck{
|
|
attributes: attributes,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (a *actionReaderStuck) Name() string {
|
|
return "reader-stuck"
|
|
}
|
|
|
|
func (a *actionReaderStuck) Run(readerGroup *ReaderGroup) bool {
|
|
reader, ok := readerGroup.ReaderByID(a.attributes.ReaderID)
|
|
if !ok {
|
|
a.logger.Info("Failed to get queue with readerID for reader stuck action", tag.QueueReaderID(a.attributes.ReaderID))
|
|
return false
|
|
}
|
|
|
|
stuckRange := NewRange(
|
|
a.attributes.CurrentWatermark,
|
|
tasks.NewKey(
|
|
a.attributes.CurrentWatermark.FireTime.Add(monitorWatermarkPrecision),
|
|
a.attributes.CurrentWatermark.TaskID,
|
|
),
|
|
)
|
|
|
|
var splitSlices []Slice
|
|
reader.SplitSlices(func(s Slice) ([]Slice, bool) {
|
|
r := s.Scope().Range
|
|
if stuckRange.ContainsRange(r) {
|
|
splitSlices = append(splitSlices, s)
|
|
return nil, true
|
|
}
|
|
|
|
remaining := make([]Slice, 0, 2)
|
|
if s.CanSplitByRange(stuckRange.InclusiveMin) {
|
|
left, right := s.SplitByRange(stuckRange.InclusiveMin)
|
|
remaining = append(remaining, left)
|
|
s = right
|
|
}
|
|
|
|
if s.CanSplitByRange(stuckRange.ExclusiveMax) {
|
|
left, right := s.SplitByRange(stuckRange.ExclusiveMax)
|
|
remaining = append(remaining, right)
|
|
s = left
|
|
}
|
|
|
|
if len(remaining) == 0 {
|
|
// s can't split by both min and max of stuck range,
|
|
// and stuck range does not contain the range of s,
|
|
// the only possible case is s is not overlapping with stuck range at all.
|
|
return nil, false
|
|
}
|
|
|
|
splitSlices = append(splitSlices, s)
|
|
return remaining, true
|
|
})
|
|
|
|
if len(splitSlices) == 0 {
|
|
return false
|
|
}
|
|
|
|
nextReader := readerGroup.GetOrCreateReader(a.attributes.ReaderID + 1)
|
|
nextReader.MergeSlices(splitSlices...)
|
|
return true
|
|
}
|