Looking to execute a graph of ops, which aren't tied to asset definitions? Check out the Op jobs documentation.
Jobs are the main unit for executing and monitoring asset definitions in Dagster. An asset job is a type of job that targets a selection of assets and can be launched:
In this section, we'll demonstrate how to create a few asset jobs that target the following assets:
from dagster import asset
@assetdefsugary_cereals()->None:
execute_query("CREATE TABLE sugary_cereals AS SELECT * FROM cereals WHERE sugar_grams > 10")@asset(deps=[sugary_cereals])defshopping_list()->None:
execute_query("CREATE TABLE shopping_list AS SELECT * FROM sugary_cereals")
To create an asset job, use define_asset_job. An asset-based job is based on the assets the job targets and their dependencies.
You can target one or multiple assets, or create multiple jobs that target overlapping sets of assets. In the following example, we have two jobs:
all_assets_job targets all assets
sugary_cereals_job targets only the sugary_cereals asset
Including the jobs in a Definitions object located at the top level of a Python module or file makes asset jobs available to the UI, GraphQL, and the command line. The Dagster tool loads that module as a code location. If you include schedules or sensors, the code location will automatically include jobs that those schedules or sensors target.
Dagster has built-in support for testing, including separating business logic from environments and setting explicit expectations on uncontrollable inputs. Refer to the Testing guide for more info and examples.