pestifer.core.controller module

A controller for the pestifer runtime. Initialization of a Controller object generates the configuration, from which the list of tasks is created. The do_tasks() method executes the tasks.

class pestifer.core.controller.Controller[source]

Bases: object

Controller class for managing the execution of tasks in the Pestifer runtime. This class initializes with a configuration and a list of user-specified tasks. It sets up the necessary file writers and creates a list of tasks to be executed. The tasks are executed in the order they are defined, and the results of each task are collected in a report. If the last task is not a pestifer.tasks.terminate.TerminateTask task, a default pestifer.tasks.terminate.TerminateTask is added to ensure proper termination.

Parameters:
  • config (Config) – The configuration object containing user specifications and settings.

  • userspecs (dict, optional) – A dictionary of user-specific configurations provided at run-time that will update the base configuration.

  • index (int, optional) – An index for the controller instance, useful for identifying multiple controllers in a run.

  • terminate (bool, optional) – If True, a default terminate task will be added if the last task is not already a TerminateTask. This ensures that the runtime will always have a way to clean up and terminate properly. Default is True.

configure(config: Config, userspecs: dict = {}, index: int = 0, terminate: bool = True)[source]
do_tasks() dict[source]

Execute the tasks in the order they were defined.

This method iterates through the list of tasks, executing each one in turn. It collects the results of each task in a report dictionary, which maps task indices to their names, indices, and results. If any task fails (i.e., returns a non-zero result), a warning is logged, and the execution of subsequent tasks is aborted.

Returns:

A dictionary containing the results of each task, with task indices as keys. Each value is itself a dictionary with the following keys:

  • taskname: The name of the task

  • taskindex: The index of the task

  • result: The task’s return code

Return type:

dict

provision_tasks()[source]
reconfigure_tasks(tasks: list[dict])[source]
classmethod spawn_subcontroller(progenitor: Controller) Controller[source]
write_complete_config(filename='complete-user.yaml')[source]

Write the complete user configuration to a YAML file. This method dumps the user configuration, including all modifications made during the execution of tasks, to a specified YAML file. The default filename is ‘complete-user.yaml’.

Parameters:

filename (str, optional) – The name of the file to which the user configuration will be written. Default is ‘complete-user.yaml’.