base_task
trestle.tasks.base_task
¤
Trestle tasks base templating.
logger
¤
Classes¤
PassFail (TaskBase)
¤
Holding pattern template for a task which does nothing and always passes.
Attributes:
Name | Type | Description |
---|---|---|
name |
str |
Name of the task. |
Source code in trestle/tasks/base_task.py
class PassFail(TaskBase):
"""
Holding pattern template for a task which does nothing and always passes.
Attributes:
name: Name of the task.
"""
name = 'pass-fail'
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""
Initialize trestle task pass-fail.
Attributes:
config_object: Config section associated with the task.
"""
super().__init__(config_object)
def print_info(self) -> None:
"""Print the help string."""
logger.info(f'Help information for {self.name} task.')
logger.info('This is a template task which reports pass fail depending on the specific configuration.')
logger.info(
'In this case if no config section is provided the task will fail. This a a task specific behavior.'
)
logger.info('Configuration flags sit under [task.pass-fail]')
logger.info('with two boolean flags')
logger.info('execute_status = True/False with a default pass')
logger.info('simulate_status = True/False with a default fail')
logger.info('Note that if the config file does not have the appropriate section this should fail.')
logger.info('The princple goal is a simple development example.')
def simulate(self) -> TaskOutcome:
"""Provide a simulated outcome."""
if self._config:
outcome = self._config.getboolean('simulate_status', fallback=True)
if outcome:
return TaskOutcome('simulated-success')
return TaskOutcome('simulated-failure')
def execute(self) -> TaskOutcome:
"""Provide a actual outcome."""
if self._config:
outcome = self._config.getboolean('execute_status', fallback=True)
if outcome:
return TaskOutcome('success')
return TaskOutcome('failure')
name: str
¤
Methods¤
__init__(self, config_object)
special
¤
Initialize trestle task pass-fail.
Attributes:
Name | Type | Description |
---|---|---|
config_object |
Config section associated with the task. |
Source code in trestle/tasks/base_task.py
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""
Initialize trestle task pass-fail.
Attributes:
config_object: Config section associated with the task.
"""
super().__init__(config_object)
execute(self)
¤
Provide a actual outcome.
Source code in trestle/tasks/base_task.py
def execute(self) -> TaskOutcome:
"""Provide a actual outcome."""
if self._config:
outcome = self._config.getboolean('execute_status', fallback=True)
if outcome:
return TaskOutcome('success')
return TaskOutcome('failure')
print_info(self)
¤
Print the help string.
Source code in trestle/tasks/base_task.py
def print_info(self) -> None:
"""Print the help string."""
logger.info(f'Help information for {self.name} task.')
logger.info('This is a template task which reports pass fail depending on the specific configuration.')
logger.info(
'In this case if no config section is provided the task will fail. This a a task specific behavior.'
)
logger.info('Configuration flags sit under [task.pass-fail]')
logger.info('with two boolean flags')
logger.info('execute_status = True/False with a default pass')
logger.info('simulate_status = True/False with a default fail')
logger.info('Note that if the config file does not have the appropriate section this should fail.')
logger.info('The princple goal is a simple development example.')
simulate(self)
¤
Provide a simulated outcome.
Source code in trestle/tasks/base_task.py
def simulate(self) -> TaskOutcome:
"""Provide a simulated outcome."""
if self._config:
outcome = self._config.getboolean('simulate_status', fallback=True)
if outcome:
return TaskOutcome('simulated-success')
return TaskOutcome('simulated-failure')
TaskBase (ABC)
¤
Abstract base class for tasks.
Attributes:
Name | Type | Description |
---|---|---|
name |
str |
Name of the task. |
Source code in trestle/tasks/base_task.py
class TaskBase(ABC):
"""
Abstract base class for tasks.
Attributes:
name: Name of the task.
"""
name: str = 'base'
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""Initialize task base and store config."""
self._config = config_object
@abstractmethod
def print_info(self) -> None:
"""Print the help string."""
@abstractmethod
def execute(self) -> TaskOutcome:
"""Execute the task including potential rollback."""
@abstractmethod
def simulate(self) -> TaskOutcome:
"""Simulate the task and report task outcome."""
name: str
¤
Methods¤
__init__(self, config_object)
special
¤
Initialize task base and store config.
Source code in trestle/tasks/base_task.py
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""Initialize task base and store config."""
self._config = config_object
execute(self)
¤
Execute the task including potential rollback.
Source code in trestle/tasks/base_task.py
@abstractmethod
def execute(self) -> TaskOutcome:
"""Execute the task including potential rollback."""
print_info(self)
¤
Print the help string.
Source code in trestle/tasks/base_task.py
@abstractmethod
def print_info(self) -> None:
"""Print the help string."""
simulate(self)
¤
Simulate the task and report task outcome.
Source code in trestle/tasks/base_task.py
@abstractmethod
def simulate(self) -> TaskOutcome:
"""Simulate the task and report task outcome."""
TaskOutcome (Enum)
¤
Enum describing possible task outcomes.
Source code in trestle/tasks/base_task.py
class TaskOutcome(Enum):
"""Enum describing possible task outcomes."""
SUCCESS = 'success'
FAILURE = 'failure'
ROLLEDBACK = 'rolledback'
SIM_SUCCESS = 'simulated-success'
SIM_FAILURE = 'simulated-failure'
NOT_IMPLEMENTED = 'not-implemented'
handler: python