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:
Common Use Cases¶
๐ Data Analysis¶
Perfect for one-off analysis tasks:
๐งช 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¶
โ๏ธ Parameter Support¶
๐ 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?¶
- Jobs vs Pipelines - Detailed comparison and decision guide