Skip to content

task

dev_tool.commands.task

log = logging.getLogger(__name__) module-attribute

TaskCommandGroup

Bases: CommandGroup

A command group for task management operations.

This class provides commands for viewing and managing background tasks, including viewing recent tasks and clearing completed tasks.

The constructor for the TaskCommandGroup class.

This method initializes the command group with the terminal interface and task manager.

Parameters:

  • terminal (Terminal | None, default: None ) –

    The blessed Terminal instance for display operations.

Source code in dev_tool/commands/task.py
def __init__(self, terminal: Terminal | None = None) -> None:
    """
    The constructor for the TaskCommandGroup class.

    This method initializes the command group with the terminal interface
    and task manager.

    :param terminal: The blessed Terminal instance for display operations.
    """

    super().__init__()

    self.interface = BaseInterface(terminal or Terminal())
    self.task_manager = TaskManager()

interface = BaseInterface(terminal or Terminal()) instance-attribute

task_manager = TaskManager() instance-attribute

__str__

The string representation of the command group.

This method returns the category name for the command group.

Returns:

  • str

    The category name as a string.

Source code in dev_tool/commands/task.py
def __str__(self) -> str:
    """
    The string representation of the command group.

    This method returns the category name for the command group.

    :return: The category name as a string.
    """

    return 'Tasks'

view_recent_tasks

A command that opens a submenu for viewing recent tasks.

This method returns a menu displaying the most recent tasks with their status and allows viewing individual task results.

Returns:

  • Menu

    A submenu for viewing recent tasks.

Source code in dev_tool/commands/task.py
@ordered_submenu(label='View recent task(s)')
def view_recent_tasks(self) -> Menu:
    """
    A command that opens a submenu for viewing recent tasks.

    This method returns a menu displaying the most recent tasks with
    their status and allows viewing individual task results.

    :return: A submenu for viewing recent tasks.
    """

    try:
        tasks = self.task_manager.get()
    except Exception as e:
        emit_error(f'Failed to get recent tasks: {e}')
        return Menu(title='View recent tasks', items=[])

    amount = 10
    recent = tasks[:amount]

    if not recent:
        return Menu(title='View recent tasks', items=[])

    items: list[Menu | MenuItem] = [
        MenuItem(
            label=self._format_label(task),
            action=DisplayAction(content=partial(self._get_task_content, task))
        )
        for task in recent
    ]

    return Menu(title='View recent tasks', items=items)

clear_completed_tasks

A command that clears all completed and failed tasks.

This method removes all tasks that have finished processing, including both successfully completed and failed tasks.

Source code in dev_tool/commands/task.py
@ordered_command(label='Clear completed task(s)')
def clear_completed_tasks(self) -> None:
    """
    A command that clears all completed and failed tasks.

    This method removes all tasks that have finished processing,
    including both successfully completed and failed tasks.
    """

    try:
        self.task_manager.clear_completed()
    except Exception as e:
        emit_error(f'Failed to clear completed tasks: {e}')