lifecycle.api.TaskExecutionHookΒΆ

class hamilton.lifecycle.api.TaskExecutionHookΒΆ

Implement this to hook into the task execution process. Tasks consist of a group of one or more nodes that are run on a task executor.

post_task_execute(*, run_id: str, task_id: str, nodes: List[Node], results: Dict[str, Any] | None, success: bool, error: Exception, spawning_task_id: str | None, purpose: None)ΒΆ

Hook called immediately after task execution. Note that this is only useful in dynamic execution, although we reserve the right to add this back into the standard hamilton execution pattern.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_id – ID of the task

  • nodes – Nodes that were executed

  • results – Results of the task

  • success – Whether or not the task executed successfully

  • error – The error that was raised, if any

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

pre_task_execute(*, run_id: str, task_id: str, nodes: List[Node], inputs: Dict[str, Any], overrides: Dict[str, Any], spawning_task_id: str | None, purpose: None)ΒΆ

Hook that is called immediately prior to task execution. Note that this is only useful in dynamic execution, although we reserve the right to add this back into the standard hamilton execution pattern.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_id – ID of the task, unique in scope of the driver.

  • nodes – Nodes that are being executed

  • inputs – Inputs to the task

  • overrides – Overrides to task execution

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

abstractmethod run_after_task_execution(*, task_id: str, run_id: str, nodes: List[HamiltonNode], results: Dict[str, Any] | None, success: bool, error: Exception, spawning_task_id: str | None, purpose: None, **future_kwargs)ΒΆ

Runs after all of the nodes associated with a task have been executed. By definition this is run inside of the executor and therefore may be run on separate or distributed processes.

Parameters:
  • task_id – ID of the task that was just executed

  • run_id – ID of the run this was under.

  • nodes – Nodes that were part of this task

  • results – Results of the task, per-node

  • success – Whether the task was successful

  • error – The error the task threw, if any

  • future_kwargs – Reserved for backwards compatibility.

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

abstractmethod run_before_task_execution(*, task_id: str, run_id: str, nodes: List[HamiltonNode], inputs: Dict[str, Any], overrides: Dict[str, Any], spawning_task_id: str | None, purpose: None, **future_kwargs)ΒΆ

Runs prior to any of the nodes associated with a task. By definition this is run inside of the executor and therefore may be run on separate or distributed processes.

Parameters:
  • task_id – ID of the task we’re launching.

  • run_id – ID of the run this is under.

  • nodes – Nodes that are part of this task

  • inputs – Inputs to the task

  • overrides – Overrides passed to the task

  • future_kwargs – Reserved for backwards compatibility.

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group