feat: expand testing
This commit is contained in:
11
data_platform/ops/__init__.py
Normal file
11
data_platform/ops/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from data_platform.ops.check_source_freshness import (
|
||||
SourceFreshnessConfig,
|
||||
check_source_freshness,
|
||||
)
|
||||
from data_platform.ops.elementary import elementary_generate_report
|
||||
|
||||
__all__ = [
|
||||
"check_source_freshness",
|
||||
"SourceFreshnessConfig",
|
||||
"elementary_generate_report",
|
||||
]
|
||||
25
data_platform/ops/check_source_freshness.py
Normal file
25
data_platform/ops/check_source_freshness.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""dbt source freshness op."""
|
||||
|
||||
from dagster import Config, OpExecutionContext, op
|
||||
from dagster_dbt import DbtCliResource
|
||||
|
||||
|
||||
class SourceFreshnessConfig(Config):
|
||||
"""Config for the source freshness op."""
|
||||
|
||||
source_name: str
|
||||
|
||||
|
||||
@op
|
||||
def check_source_freshness(
|
||||
context: OpExecutionContext,
|
||||
config: SourceFreshnessConfig,
|
||||
dbt: DbtCliResource,
|
||||
) -> None:
|
||||
"""Run dbt source freshness for the configured source."""
|
||||
list(
|
||||
dbt.cli(
|
||||
["source", "freshness", "--select", f"source:{config.source_name}"],
|
||||
context=context,
|
||||
).stream()
|
||||
)
|
||||
31
data_platform/ops/elementary.py
Normal file
31
data_platform/ops/elementary.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Elementary report generation op."""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from dagster import OpExecutionContext, op
|
||||
|
||||
_DBT_DIR = Path(__file__).parents[2] / "dbt"
|
||||
|
||||
|
||||
@op
|
||||
def elementary_generate_report(context: OpExecutionContext) -> None:
|
||||
"""Run edr report to regenerate the Elementary HTML report."""
|
||||
cmd = [
|
||||
"edr",
|
||||
"report",
|
||||
"--profiles-dir",
|
||||
str(_DBT_DIR),
|
||||
"--project-dir",
|
||||
str(_DBT_DIR),
|
||||
"--disable-open-browser",
|
||||
]
|
||||
context.log.info(f"Running: {' '.join(cmd)}")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.stdout:
|
||||
context.log.info(result.stdout)
|
||||
if result.stderr:
|
||||
context.log.warning(result.stderr)
|
||||
if result.returncode != 0:
|
||||
raise Exception(f"edr report failed with exit code {result.returncode}")
|
||||
context.log.info("Elementary report generated successfully.")
|
||||
Reference in New Issue
Block a user