Skip to main content

PluginStateManager

PluginStateManager implements PluginStateReader and PluginStateWriter using Gob encoding over byte buffers. It is initialized with the previous state from TaskAction.Status.PluginState and captures new state written by the plugin during Handle.

Methods


GetStateVersion()

@classmethod
def GetStateVersion() - > uint8

Retrieves the current version of the plugin's state. This allows callers to check the state's freshness or compatibility.

Returns

TypeDescription
uint8The version number of the current plugin state.

Get()

@classmethod
def Get(
t: interface{}
) - > (uint8, error)

Decodes the stored plugin state into the provided interface. This method is used to retrieve the plugin's previous state for processing.

Parameters

NameTypeDescription
tinterface{}An empty interface into which the stored state will be decoded. It must be a pointer to the expected state structure.

Returns

TypeDescription
(uint8, error)The version of the retrieved state and an error if decoding fails.

Put()

@classmethod
def Put(
stateVersion: uint8,
v: interface{}
) - > error

Encodes and stores the provided value as the new plugin state with a specified version. This method updates the plugin's state, which will be persisted.

Parameters

NameTypeDescription
stateVersionuint8The version number to associate with the new state. This helps in managing state compatibility.
vinterface{}The value to be encoded and stored as the new plugin state. This should be the complete state object.

Returns

TypeDescription
errorAn error if encoding or storing the state fails.

Reset()

@classmethod
def Reset() - > error

Resets the internal state manager, clearing any new state that has been written. This is useful for discarding unsaved changes or preparing for a fresh state capture.

Returns

TypeDescription
errorAn error if the reset operation encounters an issue.

GetNewState()

@classmethod
def GetNewState() - > (stateBytes[]byte, version uint8, written bool)

Retrieves the newly written state, its version, and a flag indicating if any new state was written. This method is typically called at the end of a plugin's execution to get the state to be persisted.

Returns

TypeDescription
(stateBytes[]byte, version uint8, written bool)The byte slice of the new state, its version, and a boolean indicating if new state was successfully written.