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.3 KiB
Go
87 lines
2.3 KiB
Go
package scheduler
|
|
|
|
import (
|
|
"time"
|
|
|
|
schedulespb "github.com/hanzoai/tasks/api/schedule/v1"
|
|
"github.com/hanzoai/tasks/chasm"
|
|
"github.com/hanzoai/tasks/chasm/lib/scheduler/gen/schedulerpb/v1"
|
|
schedulescommon "github.com/hanzoai/tasks/common/schedules"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
// The Backfiller component is responsible for buffering manually
|
|
// requested actions. Each backfill request has its own Backfiller node.
|
|
type Backfiller struct {
|
|
chasm.UnimplementedComponent
|
|
|
|
*schedulerpb.BackfillerState
|
|
|
|
Scheduler chasm.ParentPtr[*Scheduler]
|
|
}
|
|
|
|
type BackfillRequestType int
|
|
|
|
const (
|
|
RequestTypeTrigger BackfillRequestType = iota
|
|
RequestTypeBackfill
|
|
)
|
|
|
|
// addBackfiller returns an initialized backfiller, adding it to the scheduler's
|
|
// Backfillers.
|
|
func addBackfiller(
|
|
ctx chasm.MutableContext,
|
|
scheduler *Scheduler,
|
|
) *Backfiller {
|
|
id := schedulescommon.GenerateBackfillerID()
|
|
backfiller := newBackfillerWithState(ctx, &schedulerpb.BackfillerState{
|
|
BackfillId: id,
|
|
LastProcessedTime: timestamppb.New(ctx.Now(scheduler)),
|
|
})
|
|
|
|
if scheduler.Backfillers == nil {
|
|
scheduler.Backfillers = make(chasm.Map[string, *Backfiller])
|
|
}
|
|
scheduler.Backfillers[id] = chasm.NewComponentField(ctx, backfiller)
|
|
|
|
return backfiller
|
|
}
|
|
|
|
func newBackfillerWithState(ctx chasm.MutableContext, state *schedulerpb.BackfillerState) *Backfiller {
|
|
backfiller := &Backfiller{
|
|
BackfillerState: state,
|
|
}
|
|
backfiller.scheduleTask(ctx, chasm.TaskScheduledTimeImmediate)
|
|
return backfiller
|
|
}
|
|
|
|
// scheduleTask schedules a BackfillerTask at the given time.
|
|
func (b *Backfiller) scheduleTask(ctx chasm.MutableContext, scheduledTime time.Time) {
|
|
ctx.AddTask(b, chasm.TaskAttributes{
|
|
ScheduledTime: scheduledTime,
|
|
}, &schedulerpb.BackfillerTask{})
|
|
}
|
|
|
|
func (b *Backfiller) LifecycleState(ctx chasm.Context) chasm.LifecycleState {
|
|
return chasm.LifecycleStateRunning
|
|
}
|
|
|
|
func (b *Backfiller) RequestType() BackfillRequestType {
|
|
if b.GetTriggerRequest() != nil {
|
|
return RequestTypeTrigger
|
|
}
|
|
|
|
return RequestTypeBackfill
|
|
}
|
|
|
|
type backfillProgressResult struct {
|
|
// BufferedStarts that should be enqueued to the Invoker.
|
|
BufferedStarts []*schedulespb.BufferedStart
|
|
|
|
// High water mark for when state was last updated.
|
|
LastProcessedTime time.Time
|
|
|
|
// When true, the backfill has completed and the node can be deleted.
|
|
Complete bool
|
|
}
|