Skip to content

State

Base class for task state mnager

State

Bases: ABC

Abstract base class for a state manager.

This class is responsible for managing task states. It provides an interface for state management and captures task-related metrics.

Attributes:

Name Type Description
buffer Dict[str, Any]

Buffer for state data.

log logging.Logger

Logger for capturing logs.

task_id str

Identifier for the task.

__del__()

Destructor to flush the buffer before object deletion.

This ensures that any buffered state data is not lost when the object is deleted.

flush()

Flush the buffer to the state storage.

This method is responsible for writing the buffered state data to the underlying storage mechanism.

get(task_id, key) abstractmethod

Abstract method to get the state associated with a task and key.

Parameters:

Name Type Description Default
task_id str

The task identifier.

required
key str

The key to get the state for.

required

Returns:

Type Description
Optional[Dict[str, Any]]

Optional[Dict[str, Any]]: The state associated with the task and key, if it exists.

get_state(key)

Get the state associated with a key from the buffer or underlying storage.

Parameters:

Name Type Description Default
key str

The key to get the state for.

required

Returns:

Type Description
Optional[Dict[str, Any]]

Optional[Dict[str, Any]]: The state associated with the key.

set(task_id, key, value) abstractmethod

Abstract method to set the state associated with a task and key.

Parameters:

Name Type Description Default
task_id str

The task identifier.

required
key str

The key to set the state for.

required
value Dict[str, Any]

The state to set.

required

set_state(key, value)

Set the state associated with a key in the buffer.

Parameters:

Name Type Description Default
key str

The key to set the state for.

required
value Dict[str, Any]

The state to set.

required