This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
/
handler.go
56 lines (43 loc) · 2.32 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package interfaces
import (
"context"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/catalog"
"github.com/flyteorg/flytepropeller/pkg/controller/executors"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/handler"
"github.com/flyteorg/flytestdlib/promutils"
)
//go:generate mockery -all -case=underscore
// NodeExecutor defines the interface for handling a single Flyte Node of any Node type.
type NodeExecutor interface {
HandleNode(ctx context.Context, dag executors.DAGStructure, nCtx NodeExecutionContext, h NodeHandler) (NodeStatus, error)
Abort(ctx context.Context, h NodeHandler, nCtx NodeExecutionContext, reason string, finalTransition bool) error
Finalize(ctx context.Context, h NodeHandler, nCtx NodeExecutionContext) error
}
// Interface that should be implemented for a node type.
type NodeHandler interface {
// Method to indicate that finalize is required for this handler
FinalizeRequired() bool
// Setup should be called, before invoking any other methods of this handler in a single thread context
Setup(ctx context.Context, setupContext SetupContext) error
// Core method that should handle this node
Handle(ctx context.Context, executionContext NodeExecutionContext) (handler.Transition, error)
// This method should be invoked to indicate the node needs to be aborted.
Abort(ctx context.Context, executionContext NodeExecutionContext, reason string) error
// This method is always called before completing the node, if FinalizeRequired returns true.
// It is guaranteed that Handle -> (happens before) -> Finalize. Abort -> finalize may be repeated multiple times
Finalize(ctx context.Context, executionContext NodeExecutionContext) error
}
// CacheableNodeHandler is a node that supports caching
type CacheableNodeHandler interface {
NodeHandler
// GetCatalogKey returns the unique key for the node represented by the NodeExecutionContext
GetCatalogKey(ctx context.Context, executionContext NodeExecutionContext) (catalog.Key, error)
// IsCacheable returns two booleans representing if the node represented by the
// NodeExecutionContext is cacheable and cache serializable respectively.
IsCacheable(ctx context.Context, executionContext NodeExecutionContext) (bool, bool, error)
}
type SetupContext interface {
EnqueueOwner() func(string)
OwnerKind() string
MetricsScope() promutils.Scope
}