Skip to content

Task

Base class for Task

Task

Bases: ABC

🛠️ Task: Class for managing tasks.

This class provides a foundation for creating and managing tasks. Each task has a unique identifier and can be associated with specific input and output data.

Attributes:

  • id (uuid.UUID): Unique identifier for the task.
  • input (Input): Configuration for input data.
  • output (Output): Configuration for output data.

Usage:

task = Task()
task.execute("fetch_data")

!!! note Extend this class to implement specific task functionalities.

__init__(id=None)

Initialize a new task.

Parameters:

Name Type Description Default
input Input

Configuration for input data.

required
output Output

Configuration for output data.

required

__repr__()

Return a string representation of the task.

Returns:

Name Type Description
str str

A string representation of the task.

execute(method_name, *args, **kwargs)

🚀 Execute a given fetch_* method if it exists.

Parameters:

Name Type Description Default
method_name str

The name of the fetch_* method to execute.

required
*args

Positional arguments to pass to the method.

()
**kwargs

Keyword arguments to pass to the method.

{}

Returns:

Name Type Description
Any Any

The result of the fetch_* method, or None if the method does not exist.

Raises:

Type Description
AttributeError

If the specified method doesn't exist.

get_methods() staticmethod

📜 Get all the fetch_* methods and their parameters along with their default values and docstrings.

Returns:

Type Description
List[Tuple[str, List[str], Optional[str]]]

List[Tuple[str, List[str], str]]: A list of tuples, where each tuple contains the name of a fetch_* method,

List[Tuple[str, List[str], Optional[str]]]

a list of its parameters along with their default values, and its docstring.

print_help() staticmethod

🖨️ Pretty print the fetch_* methods and their parameters along with their default values and docstrings. Also prints the class's docstring and init parameters.