From 62d984b820286dc553127f900e1ad7a10a64f7c6 Mon Sep 17 00:00:00 2001 From: yuhan Date: Wed, 14 Dec 2022 14:53:18 -0800 Subject: [PATCH] convert-examples-repo-to-defs cloud nux quickstart_snowflake --- examples/quickstart_snowflake/pyproject.toml | 3 ++ .../quickstart_snowflake/__init__.py | 36 ++++++++++++++++- .../quickstart_snowflake/repository.py | 40 ------------------- .../quickstart_snowflake_tests/test_defs.py | 5 +++ examples/quickstart_snowflake/workspace.yaml | 2 - 5 files changed, 43 insertions(+), 43 deletions(-) delete mode 100644 examples/quickstart_snowflake/quickstart_snowflake/repository.py create mode 100644 examples/quickstart_snowflake/quickstart_snowflake_tests/test_defs.py delete mode 100644 examples/quickstart_snowflake/workspace.yaml diff --git a/examples/quickstart_snowflake/pyproject.toml b/examples/quickstart_snowflake/pyproject.toml index fed528d4a7a14..b4374f4f7c76d 100644 --- a/examples/quickstart_snowflake/pyproject.toml +++ b/examples/quickstart_snowflake/pyproject.toml @@ -1,3 +1,6 @@ [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.dagster] +module_name = "quickstart_snowflake" diff --git a/examples/quickstart_snowflake/quickstart_snowflake/__init__.py b/examples/quickstart_snowflake/quickstart_snowflake/__init__.py index fc1fa6b8b22c1..8f81cc47c25e4 100644 --- a/examples/quickstart_snowflake/quickstart_snowflake/__init__.py +++ b/examples/quickstart_snowflake/quickstart_snowflake/__init__.py @@ -1 +1,35 @@ -from .repository import quickstart_snowflake +from dagster_snowflake import build_snowflake_io_manager +from dagster_snowflake_pandas import SnowflakePandasTypeHandler + +from dagster import ( + Definitions, + ScheduleDefinition, + define_asset_job, + load_assets_from_package_module, +) + +from . import assets + +daily_refresh_schedule = ScheduleDefinition( + job=define_asset_job(name="all_assets_job"), cron_schedule="0 0 * * *" +) + + +defs = Definitions( + assets=load_assets_from_package_module(assets), + resources={ + "io_manager": build_snowflake_io_manager([SnowflakePandasTypeHandler()]).configured( + # Read about using environment variables and secrets in Dagster: + # https://docs.dagster.io/guides/dagster/using-environment-variables-and-secrets + { + "account": {"env": "SNOWFLAKE_ACCOUNT"}, + "user": {"env": "SNOWFLAKE_USER"}, + "password": {"env": "SNOWFLAKE_PASSWORD"}, + "warehouse": {"env": "SNOWFLAKE_WAREHOUSE"}, + "database": {"env": "SNOWFLAKE_DATABASE"}, + "schema": {"env": "SNOWFLAKE_SCHEMA"}, + } + ), + }, + schedules=[daily_refresh_schedule], +) diff --git a/examples/quickstart_snowflake/quickstart_snowflake/repository.py b/examples/quickstart_snowflake/quickstart_snowflake/repository.py deleted file mode 100644 index 5edfcbcdf8168..0000000000000 --- a/examples/quickstart_snowflake/quickstart_snowflake/repository.py +++ /dev/null @@ -1,40 +0,0 @@ -from dagster_snowflake import build_snowflake_io_manager -from dagster_snowflake_pandas import SnowflakePandasTypeHandler - -from dagster import ( - ScheduleDefinition, - define_asset_job, - load_assets_from_package_module, - repository, - with_resources, -) - -from . import assets - -daily_refresh_schedule = ScheduleDefinition( - job=define_asset_job(name="all_assets_job"), cron_schedule="0 0 * * *" -) - - -@repository -def quickstart_snowflake(): - return [ - *with_resources( - load_assets_from_package_module(assets), - resource_defs={ - "io_manager": build_snowflake_io_manager([SnowflakePandasTypeHandler()]).configured( - # Read about using environment variables and secrets in Dagster: - # https://docs.dagster.io/guides/dagster/using-environment-variables-and-secrets - { - "account": {"env": "SNOWFLAKE_ACCOUNT"}, - "user": {"env": "SNOWFLAKE_USER"}, - "password": {"env": "SNOWFLAKE_PASSWORD"}, - "warehouse": {"env": "SNOWFLAKE_WAREHOUSE"}, - "database": {"env": "SNOWFLAKE_DATABASE"}, - "schema": {"env": "SNOWFLAKE_SCHEMA"}, - } - ), - }, - ), - daily_refresh_schedule, - ] diff --git a/examples/quickstart_snowflake/quickstart_snowflake_tests/test_defs.py b/examples/quickstart_snowflake/quickstart_snowflake_tests/test_defs.py new file mode 100644 index 0000000000000..236da155b85b2 --- /dev/null +++ b/examples/quickstart_snowflake/quickstart_snowflake_tests/test_defs.py @@ -0,0 +1,5 @@ +from quickstart_snowflake import defs + + +def test_def_can_load(): + assert defs.get_job_def("all_assets_job") diff --git a/examples/quickstart_snowflake/workspace.yaml b/examples/quickstart_snowflake/workspace.yaml deleted file mode 100644 index d8e5020d704f9..0000000000000 --- a/examples/quickstart_snowflake/workspace.yaml +++ /dev/null @@ -1,2 +0,0 @@ -load_from: - - python_package: quickstart_snowflake