Overview
This page provides an overview of how the package internally works. See the Getting Started guide for a quick introduction to dagster jobs.
Dynamic jobs
Dagster jobs are compiled by calling OpDefinition
and GraphDefinition
instances within the context of a function decorated by @dagster.job
.
Even though runtime calculations using Python-native functions can only occur
inside dagster ops, it is possible to dynamically change how a job is created
using this mechanism.
Consider the following job:
This is a job that executes the same op three times. Instead, a Python for loop could be used to obtain the same behavior:
Extending this idea further, we may consider the number of calls to
return_five
to not be fixed. It may instead depend on a value obtained from
elsewhere. To this end a new function is introduced as:
This approach is widely used and is known as the factory pattern. A composable graph builds on this concept by formalizing the interface to the builder and simplifying the definition of the job.
Further reading
- ”Factory Patterns in Python” on the dagster blog.
- ”Unlocking Flexible Pipelines: Customizing the Asset Decorator” on the dagster blog.
- ”Abstracting Pipelines for Analysts with a YAML DSL” on the dagster blog.
- YAML DSL for Asset Graphs Example on dagster github.