Files
tasks/service/history/ndc/buffer_event_flusher.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

87 lines
2.2 KiB
Go

//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination buffer_event_flusher_mock.go
package ndc
import (
"context"
"github.com/hanzoai/tasks/common/cluster"
"github.com/hanzoai/tasks/common/log"
historyi "github.com/hanzoai/tasks/service/history/interfaces"
wcache "github.com/hanzoai/tasks/service/history/workflow/cache"
)
type (
BufferEventFlusher interface {
flush(
ctx context.Context,
) (historyi.WorkflowContext, historyi.MutableState, error)
}
BufferEventFlusherImpl struct {
shardContext historyi.ShardContext
clusterMetadata cluster.Metadata
wfContext historyi.WorkflowContext
mutableState historyi.MutableState
logger log.Logger
}
)
var _ BufferEventFlusher = (*BufferEventFlusherImpl)(nil)
func NewBufferEventFlusher(
shardContext historyi.ShardContext,
wfContext historyi.WorkflowContext,
mutableState historyi.MutableState,
logger log.Logger,
) *BufferEventFlusherImpl {
return &BufferEventFlusherImpl{
shardContext: shardContext,
clusterMetadata: shardContext.GetClusterMetadata(),
wfContext: wfContext,
mutableState: mutableState,
logger: logger,
}
}
func (r *BufferEventFlusherImpl) flush(
ctx context.Context,
) (historyi.WorkflowContext, historyi.MutableState, error) {
// check whether there are buffered events, if so, flush it
// NOTE: buffered events does not show in version history or next event id
if !r.mutableState.HasBufferedEvents() {
if r.mutableState.HasStartedWorkflowTask() && r.mutableState.IsTransientWorkflowTask() {
if err := r.mutableState.ClearTransientWorkflowTask(); err != nil {
return nil, nil, err
}
// now transient task is gone
}
return r.wfContext, r.mutableState, nil
}
targetWorkflow := NewWorkflow(
r.clusterMetadata,
r.wfContext,
r.mutableState,
wcache.NoopReleaseFn,
)
if err := targetWorkflow.FlushBufferedEvents(); err != nil {
return nil, nil, err
}
// the workflow must be updated as active, to send out replication tasks
if err := targetWorkflow.context.UpdateWorkflowExecutionAsActive(
ctx,
r.shardContext,
); err != nil {
return nil, nil, err
}
r.wfContext = targetWorkflow.GetContext()
r.mutableState = targetWorkflow.GetMutableState()
return r.wfContext, r.mutableState, nil
}