Files
tasks/service/history/ndc/events_reapplier.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## 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`.
2025-05-01 18:50:21 -07:00

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 "go.temporal.io/server/api/enums/v1"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/service/history/hsm"
historyi "go.temporal.io/server/service/history/interfaces"
"go.temporal.io/server/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() {
if _, err := ms.AddWorkflowTaskScheduledEvent(
false,
enumsspb.WORKFLOW_TASK_TYPE_NORMAL,
); err != nil {
return nil, err
}
}
return reappliedEvents, nil
}