shared

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Separator is used to on translating keys to/from flat maps
	Separator = "/"
)

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *waiter

FromContext retrieves a waiter from the current context or returns nil if there is none.

func InformOnWaiting

func InformOnWaiting(log logr.Logger, period time.Duration, message string, keysAndValues ...any) *waiter

InformOnWaiting periodically prints a message until stopped.

func IsValidValue

func IsValidValue(value string) bool

IsValidValue returns true if an exported value is valid, i.e. not empty and not special value for deleted.

func LogFromContext

func LogFromContext(ctx context.Context) logr.Logger

LogFromContext returns the log from the context when called within a task function added with the `AddTask` method. If no logger is present, a new noop-logger will be returned.

Types

type BasicFlowContext

type BasicFlowContext struct {
	PersistInterval time.Duration
	// contains filtered or unexported fields
}

BasicFlowContext provides logic for persisting the state and add tasks to the flow graph.

func NewBasicFlowContext

func NewBasicFlowContext() *BasicFlowContext

NewBasicFlowContext creates a new `BasicFlowContext`.

func (*BasicFlowContext) AddTask

func (c *BasicFlowContext) AddTask(g *flow.Graph, name string, fn flow.TaskFn, options ...TaskOption) flow.TaskIDer

AddTask adds a wrapped task for the given task function and options.

func (*BasicFlowContext) PersistState

func (c *BasicFlowContext) PersistState(ctx context.Context) error

PersistState persists the internal state to the provider status.

func (*BasicFlowContext) WithLogger

func (c *BasicFlowContext) WithLogger(log logr.Logger) *BasicFlowContext

WithLogger injects the given logger into the context.

func (*BasicFlowContext) WithPersist

func (c *BasicFlowContext) WithPersist(task flow.TaskFn) *BasicFlowContext

WithPersist is the Task that will be called after each successful node directly after the node execution.

func (*BasicFlowContext) WithSpan

func (c *BasicFlowContext) WithSpan() *BasicFlowContext

WithSpan when enabled will log the total execution time for the task on Info level.

type FlatMap

type FlatMap map[string]string

FlatMap is a semantic name for string map used for importing and exporting

type TaskOption

type TaskOption struct {
	Dependencies []flow.TaskIDer
	Timeout      time.Duration
	DoIf         *bool
}

TaskOption contains options for created flow tasks

func Dependencies

func Dependencies(dependencies ...flow.TaskIDer) TaskOption

Dependencies creates a TaskOption for dependencies

func DoIf

func DoIf(condition bool) TaskOption

DoIf creates a TaskOption for DoIf

func Timeout

func Timeout(timeout time.Duration) TaskOption

Timeout creates a TaskOption for Timeout

type Timestamper

type Timestamper interface {
	Now() time.Time
}

Timestamper is an interface around time package.

var DefaultTimer Timestamper = TimestamperFn(time.Now)

DefaultTimer is the default implementation for Timestamper used in the package.

type TimestamperFn

type TimestamperFn func() time.Time

TimestamperFn is an implementation of the Timestamper interface using a function.

func (TimestamperFn) Now

func (t TimestamperFn) Now() time.Time

Now returns the value of time.Now().

type Whiteboard

type Whiteboard interface {
	IsEmpty() bool

	// GetChild returns a sub-whiteboard for the given key. If no child exists with this name, it is created automatically.
	// Each child has its own lock.
	GetChild(key string) Whiteboard
	// HasChild returns true if there is a non-empty child for that key
	HasChild(key string) bool
	// GetChildrenKeys returns all children keys
	GetChildrenKeys() []string

	// Get returns a valid value or nil (never "" or special deleted value)
	Get(key string) *string
	Set(key, id string)
	Delete(key string)
	SetPtr(key string, id *string)
	IsAlreadyDeleted(key string) bool
	SetAsDeleted(key string)
	// Keys returns all stored keys, even for deleted ones
	Keys() []string
	// AsMap returns a map with all valid key/values
	AsMap() map[string]string

	GetObject(key string) any
	SetObject(key string, obj any)
	DeleteObject(key string)
	HasObject(key string) bool
	ObjectKeys() []string

	// ImportFromFlatMap reconstructs the hierarchical structure from a flat map containing path-like keys
	ImportFromFlatMap(data FlatMap)
	// ExportAsFlatMap exports the hierarchical structure to a flat map with path-like keys. Objects are ignored.
	ExportAsFlatMap() FlatMap

	// CurrentGeneration returns current generation, which increments with any change
	CurrentGeneration() int64
}

Whiteboard is a hierarchical key/value store for the internal state. It is safe to be used concurrently. Additionally, it can cache objects for use in subsequent flow task.

func NewWhiteboard

func NewWhiteboard() Whiteboard

NewWhiteboard creates an empty whiteboard.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL