Skip to content

Jobs: Run Functions Once ๐ŸŽฏ

Jobs are Runnable's solution for one-time function execution. Perfect for standalone tasks, testing, analysis, and automation scripts.

What Are Jobs?

Jobs wrap your Python functions to provide:

  • Execution tracking - Know what ran, when, and what happened
  • Parameter management - Pass configuration from files or environment
  • Output capture - Automatically store results and logs
  • Error handling - Graceful failure management
  • Reproducibility - Consistent execution across environments

Quick Start

from runnable import PythonJob

def analyze_data():
    """A simple analysis function."""
    data = [1, 2, 3, 4, 5]
    result = sum(data) / len(data)
    print(f"Average: {result}")
    return result

def main():
    job = PythonJob(function=analyze_data)
    job.execute()
    return job

if __name__ == "__main__":
    main()
See complete runnable code
examples/11-jobs/python_tasks.py
"""
You can execute this pipeline by:

    python examples/01-tasks/python_tasks.py

The stdout of "Hello World!" would be captured as execution
log and stored in the catalog.

An example of the catalog structure:

.catalog
โ””โ”€โ”€ baked-heyrovsky-0602
    โ””โ”€โ”€ hello.execution.log

2 directories, 1 file


The hello.execution.log has the captured stdout of "Hello World!".
"""

from examples.common.functions import hello
from runnable import PythonJob


def main():
    job = PythonJob(function=hello)

    job.execute()

    return job


if __name__ == "__main__":
    main()

Try it now:

uv run examples/11-jobs/python_tasks.py

Common Use Cases

๐Ÿ“Š Data Analysis

Perfect for one-off analysis tasks:

def monthly_sales_analysis():
    # run a notebook

๐Ÿงช Function Testing

Test your functions in isolation:

def test_my_algorithm():
    # Test edge cases, validate outputs
    assert my_algorithm([1, 2, 3]) == expected_result

๐Ÿ“ Report Generation

Generate standalone reports:

def generate_weekly_report():
    # Collect data, create visualizations, export PDF
    return "report_2024_week_47.pdf"

Job Types

Runnable supports multiple job types for different scenarios:

Job Type Purpose Example
PythonJob Execute Python functions Data analysis, calculations
NotebookJob Run Jupyter notebooks Interactive analysis, reports
ShellJob Execute shell commands System operations, deployments

Key Features

โœ… Simple Execution

job = PythonJob(function=my_function)
job.execute()

โš™๏ธ Parameter Support

job.execute(parameters_file="config.yaml")

๐Ÿ“ Automatic Output Storage

  • Execution logs captured automatically
  • Results stored in catalog
  • Reproducible execution history

When to Use Jobs vs Pipelines

Scenario Use Jobs Use Pipelines
Single function to run โœ… โŒ
Testing a function โœ… โŒ
One-off analysis โœ… โŒ
Multi-step workflow โŒ โœ…
Data dependencies between steps โŒ โœ…
Reproducible processes โŒ โœ…

Start Simple, Grow Complex

Start with a Job to test your function, then evolve it into a Pipeline when you need multiple steps or complex workflows.

What's Next?