-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to create discoverable jobs in the asset files (#2153)
- Loading branch information
Showing
5 changed files
with
180 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import typing as t | ||
|
||
from oso_dagster.factories.common import ( | ||
AssetFactoryResponse, | ||
EarlyResourcesAssetFactory, | ||
FactoryJobDefinition, | ||
early_resources_asset_factory, | ||
) | ||
|
||
|
||
def discoverable_jobs(dependencies: t.Optional[t.List[t.Any]] = None): | ||
"""A decorator for defining a set of automatically loaded jobs. | ||
This does this by generating an AssetFactoryResponse with the jobs | ||
configured. This is useful if you need to create jobs that span multiple | ||
assets that aren't all created from a single factory""" | ||
dependencies = dependencies or [] | ||
for dep in dependencies: | ||
assert isinstance(dep, EarlyResourcesAssetFactory) | ||
|
||
def _decorated(f: t.Callable[..., t.Iterable[FactoryJobDefinition]]): | ||
@early_resources_asset_factory(caller_depth=2, dependencies=dependencies) | ||
def _jobs(dependencies: t.List[AssetFactoryResponse]): | ||
if dependencies: | ||
jobs = list(f(dependencies=dependencies)) | ||
else: | ||
jobs = list(f()) | ||
return AssetFactoryResponse(assets=[], jobs=jobs) | ||
|
||
return _jobs | ||
|
||
return _decorated |
Oops, something went wrong.