Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:173TECH Sayn TaskWrapper

From Leeroopedia
Knowledge Sources
Domains Task_Lifecycle, DAG_Management
Last Updated 2026-10-17 00:00 GMT

Overview

Concrete tool for managing the full lifecycle of a SAYN task — configuration, setup, execution, and status tracking — acting as the bridge between the DAG and the task runner.

Description

The TaskWrapper class wraps a task runner (e.g., SqlTask, CopyTask, PythonTask) and manages its lifecycle:

  • config(): Creates the runner instance, compiles YAML properties, calls runner.config(), collects sources/outputs
  • setup(): Sets in_query flag, handles from_prod recompilation, calls runner.setup()
  • execute_task(): Dispatches to runner.run(), runner.compile(), or runner.test() based on command
  • src()/out(): Resolves database object names via DbObjectCompiler and tracks used connections
  • set_parents(): Infers implicit parent dependencies from source→output mapping
  • check_skip(): Determines if the task should be skipped due to parent failures

Usage

Used internally by App.set_tasks and App.execute_dag. Not instantiated directly by users.

Code Reference

Source Location

  • Repository: SAYN
  • File: sayn/tasks/task_wrapper.py
  • Lines: L29-471 (full class)

Signature

class TaskWrapper:
    name: str
    group: str
    tags: Set[str]
    parent_names: Set[str]
    sources: Set[DbObject]
    outputs: Set[DbObject]
    used_connections: Set[str]
    in_query: bool
    runner: Optional[Task]
    status: TaskStatus

    def __init__(
        self,
        group: str,
        name: str,
        task_type: str,
        on_fail: str,
        parent_names: Set[str],
        sources: Set[str],
        outputs: Set[str],
        tags: Set[str],
        tracker,
        task_class,
        connections: Dict[str, Database],
        default_db: str,
        run_arguments: RunArguments,
        compiler: Compiler,
        db_object_compiler: DbObjectCompiler,
    )

    def config(self, task_config: Dict, project_parameters: Dict, task_parameters: Dict) -> Result
    def setup(self, in_query: bool, sources_from_prod: Set[DbObject]) -> Result
    def execute_task(self, command: str) -> Result
    def set_parents(self, all_tasks: Dict[str, TaskWrapper], output_to_task: Dict) -> Result
    def src(self, obj: str, connection=None, level=None) -> str
    def out(self, obj: str, connection=None, level=None) -> str
    def has_tests(self) -> bool

Import

from sayn.tasks.task_wrapper import TaskWrapper

I/O Contract

Inputs

Name Type Required Description
task_config Dict[str, Any] Yes Task definition from YAML
project_parameters Dict[str, Any] Yes Project-level parameters
task_parameters Dict[str, Any] No Task-specific parameters
in_query bool Yes (setup) Whether task is selected for execution
command str Yes (execute) "run", "compile", or "test"

Outputs

Name Type Description
status TaskStatus Current lifecycle status
sources Set[DbObject] Resolved source objects
outputs Set[DbObject] Resolved output objects
result Result Ok/Err from execution

Usage Examples

Internal Usage (App lifecycle)

# App.set_tasks creates TaskWrapper instances:
from sayn.tasks.task_wrapper import TaskWrapper

task_wrapper = TaskWrapper(
    group="models",
    name="model_users",
    task_type="sql",
    on_fail="skip",
    parent_names=set(),
    sources={"raw.users"},
    outputs={"analytics.users"},
    tags={"incremental"},
    tracker=task_tracker,
    task_class=SqlTask,
    connections=connections,
    default_db="warehouse",
    run_arguments=run_arguments,
    compiler=compiler,
    db_object_compiler=db_object_compiler,
)

# Configure the task
result = task_wrapper.config(task_config, project_parameters, task_parameters)

# Setup (with in_query=True for tasks to execute)
result = task_wrapper.setup(in_query=True, sources_from_prod=set())

# Execute
result = task_wrapper.execute_task("run")
print(task_wrapper.status)  # TaskStatus.SUCCEEDED or TaskStatus.FAILED

Source/Output Resolution

# During config, src() and out() resolve object names:
resolved_source = task_wrapper.src("raw.users", connection="warehouse")
# Returns: "dev_raw.users" (with dev prefix applied)

resolved_output = task_wrapper.out("analytics.users", connection="warehouse")
# Returns: "dev_analytics.users"

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment