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).
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination events_reapplier_mock.go
|
|
|
|
package ndc
|
|
|
|
import (
|
|
"context"
|
|
|
|
historypb "go.temporal.io/api/history/v1"
|
|
"go.temporal.io/api/serviceerror"
|
|
enumsspb "github.com/hanzoai/tasks/api/enums/v1"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
"github.com/hanzoai/tasks/service/history/hsm"
|
|
historyi "github.com/hanzoai/tasks/service/history/interfaces"
|
|
"github.com/hanzoai/tasks/service/history/workflow/update"
|
|
)
|
|
|
|
type (
|
|
EventsReapplier interface {
|
|
ReapplyEvents(
|
|
ctx context.Context,
|
|
ms historyi.MutableState,
|
|
updateRegistry update.Registry,
|
|
historyEvents []*historypb.HistoryEvent,
|
|
runID string,
|
|
) ([]*historypb.HistoryEvent, error)
|
|
}
|
|
|
|
EventsReapplierImpl struct {
|
|
stateMachineRegistry *hsm.Registry
|
|
metricsHandler metrics.Handler
|
|
logger log.Logger
|
|
}
|
|
)
|
|
|
|
func NewEventsReapplier(
|
|
stateMachineRegistry *hsm.Registry,
|
|
metricsHandler metrics.Handler,
|
|
logger log.Logger,
|
|
) *EventsReapplierImpl {
|
|
|
|
return &EventsReapplierImpl{
|
|
stateMachineRegistry: stateMachineRegistry,
|
|
metricsHandler: metricsHandler,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (r *EventsReapplierImpl) ReapplyEvents(
|
|
ctx context.Context,
|
|
ms historyi.MutableState,
|
|
updateRegistry update.Registry,
|
|
historyEvents []*historypb.HistoryEvent,
|
|
runID string,
|
|
) ([]*historypb.HistoryEvent, error) {
|
|
// sanity check workflow still running
|
|
if !ms.IsWorkflowExecutionRunning() {
|
|
return nil, serviceerror.NewInternal("unable to reapply events to closed workflow.")
|
|
}
|
|
reappliedEvents, err := reapplyEvents(ctx, ms, updateRegistry, r.stateMachineRegistry, historyEvents, nil, runID, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(reappliedEvents) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
if !ms.IsWorkflowExecutionRunning() {
|
|
// workflow is closed after reapplying events, no need to schedule workflow task
|
|
return reappliedEvents, nil
|
|
}
|
|
|
|
// After reapply event, checking if we should schedule a workflow task
|
|
if ms.IsWorkflowPendingOnWorkflowTaskBackoff() {
|
|
// Do not create workflow task when the workflow has first workflow task backoff and execution is not started yet
|
|
return reappliedEvents, nil
|
|
}
|
|
|
|
if !ms.HasPendingWorkflowTask() && !ms.IsWorkflowExecutionStatusPaused() {
|
|
if _, err := ms.AddWorkflowTaskScheduledEvent(
|
|
false,
|
|
enumsspb.WORKFLOW_TASK_TYPE_NORMAL,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return reappliedEvents, nil
|
|
}
|