mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-02 12:22:18 +00:00
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.
Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)
New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.
Build: go build ./cmd/tasksd → 10 MB
Vet: go vet ./... → clean
Boot: tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI: /_/tasks/, / → 200 (embedded Vite bundle)
ZAP: _tasks._tcp on :9999 (mDNS disabled; direct connect)
go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
182 lines
5.4 KiB
Go
182 lines
5.4 KiB
Go
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination delete_manager_mock.go
|
|
|
|
package deletemanager
|
|
|
|
import (
|
|
"context"
|
|
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
"go.temporal.io/server/common/clock"
|
|
"go.temporal.io/server/common/definition"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
"go.temporal.io/server/service/history/configs"
|
|
historyi "go.temporal.io/server/service/history/interfaces"
|
|
"go.temporal.io/server/service/history/tasks"
|
|
"go.temporal.io/server/service/history/workflow"
|
|
wcache "go.temporal.io/server/service/history/workflow/cache"
|
|
)
|
|
|
|
type (
|
|
DeleteManager interface {
|
|
AddDeleteExecutionTask(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
ms historyi.MutableState,
|
|
) error
|
|
DeleteWorkflowExecution(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
weCtx historyi.WorkflowContext,
|
|
ms historyi.MutableState,
|
|
stage *tasks.DeleteWorkflowExecutionStage,
|
|
) error
|
|
DeleteWorkflowExecutionByRetention(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
weCtx historyi.WorkflowContext,
|
|
ms historyi.MutableState,
|
|
stage *tasks.DeleteWorkflowExecutionStage,
|
|
) error
|
|
}
|
|
|
|
DeleteManagerImpl struct {
|
|
shardContext historyi.ShardContext
|
|
workflowCache wcache.Cache
|
|
config *configs.Config
|
|
metricsHandler metrics.Handler
|
|
timeSource clock.TimeSource
|
|
visibilityManager manager.VisibilityManager
|
|
}
|
|
)
|
|
|
|
var _ DeleteManager = (*DeleteManagerImpl)(nil)
|
|
|
|
func NewDeleteManager(
|
|
shardContext historyi.ShardContext,
|
|
cache wcache.Cache,
|
|
config *configs.Config,
|
|
timeSource clock.TimeSource,
|
|
visibilityManager manager.VisibilityManager,
|
|
) *DeleteManagerImpl {
|
|
deleteManager := &DeleteManagerImpl{
|
|
shardContext: shardContext,
|
|
workflowCache: cache,
|
|
metricsHandler: shardContext.GetMetricsHandler(),
|
|
config: config,
|
|
timeSource: timeSource,
|
|
visibilityManager: visibilityManager,
|
|
}
|
|
|
|
return deleteManager
|
|
}
|
|
|
|
func (m *DeleteManagerImpl) AddDeleteExecutionTask(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
ms historyi.MutableState,
|
|
) error {
|
|
return AddDeleteExecutionTask(ctx, m.shardContext, nsID, we, ms)
|
|
}
|
|
|
|
// AddDeleteExecutionTask creates a DeleteExecutionTask and adds it to the shard's task queue.
|
|
// This is a package-level function so it can be used by callers that don't have a DeleteManager instance.
|
|
func AddDeleteExecutionTask(
|
|
ctx context.Context,
|
|
shardContext historyi.ShardContext,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
ms historyi.MutableState,
|
|
) error {
|
|
taskGenerator := workflow.GetTaskGeneratorProvider().NewTaskGenerator(shardContext, ms)
|
|
|
|
// We can make this task immediately because the task itself will keep rescheduling itself until the
|
|
// execution is closed before actually deleting it.
|
|
deleteTask, err := taskGenerator.GenerateDeleteExecutionTask()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return shardContext.AddTasks(ctx, &persistence.AddHistoryTasksRequest{
|
|
ShardID: shardContext.GetShardID(),
|
|
NamespaceID: nsID.String(),
|
|
WorkflowID: we.GetWorkflowId(),
|
|
ArchetypeID: ms.ChasmTree().ArchetypeID(),
|
|
Tasks: map[tasks.Category][]tasks.Task{
|
|
tasks.CategoryTransfer: {deleteTask},
|
|
},
|
|
})
|
|
}
|
|
|
|
func (m *DeleteManagerImpl) DeleteWorkflowExecution(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
weCtx historyi.WorkflowContext,
|
|
ms historyi.MutableState,
|
|
stage *tasks.DeleteWorkflowExecutionStage,
|
|
) error {
|
|
|
|
return m.deleteWorkflowExecutionInternal(ctx, nsID, we, weCtx, ms, stage, m.metricsHandler.WithTags(metrics.OperationTag(metrics.HistoryDeleteWorkflowExecutionScope)))
|
|
}
|
|
|
|
func (m *DeleteManagerImpl) DeleteWorkflowExecutionByRetention(
|
|
ctx context.Context,
|
|
nsID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
weCtx historyi.WorkflowContext,
|
|
ms historyi.MutableState,
|
|
stage *tasks.DeleteWorkflowExecutionStage,
|
|
) error {
|
|
// Skip replication for retention-based deletion. Both clusters have independent retention
|
|
// timers and will delete on their own schedule.
|
|
stage.MarkProcessed(tasks.DeleteWorkflowExecutionStageReplication)
|
|
|
|
return m.deleteWorkflowExecutionInternal(ctx, nsID, we, weCtx, ms, stage, m.metricsHandler.WithTags(metrics.OperationTag(metrics.HistoryProcessDeleteHistoryEventScope)))
|
|
}
|
|
|
|
func (m *DeleteManagerImpl) deleteWorkflowExecutionInternal(
|
|
ctx context.Context,
|
|
namespaceID namespace.ID,
|
|
we *commonpb.WorkflowExecution,
|
|
weCtx historyi.WorkflowContext,
|
|
ms historyi.MutableState,
|
|
stage *tasks.DeleteWorkflowExecutionStage,
|
|
metricsHandler metrics.Handler,
|
|
) error {
|
|
|
|
currentBranchToken, err := ms.GetCurrentBranchToken()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
executionInfo := ms.GetExecutionInfo()
|
|
if err := m.shardContext.DeleteWorkflowExecution(
|
|
ctx,
|
|
definition.WorkflowKey{
|
|
NamespaceID: namespaceID.String(),
|
|
WorkflowID: we.GetWorkflowId(),
|
|
RunID: we.GetRunId(),
|
|
},
|
|
ms.ChasmTree().ArchetypeID(),
|
|
currentBranchToken,
|
|
executionInfo.GetCloseVisibilityTaskId(),
|
|
executionInfo.GetCloseTime().AsTime(),
|
|
stage,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Clear workflow execution context here to prevent further readers to get stale copy of non-exiting workflow execution.
|
|
weCtx.Clear()
|
|
|
|
metrics.WorkflowCleanupDeleteCount.With(metricsHandler).Record(1)
|
|
return nil
|
|
}
|