Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hex Assets #105

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/dagster-hex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
---

## 0.1.5 - UNRELEASED
### Added

- Hex project asset definition with `build_hex_asset` function using the project_id
- Update to hex resource to sync with new hex api updates to deprecate `update_cache` and add `use_cached_sql` instead.

## 0.1.4 - UNRELEASED

### Added
Expand Down
77 changes: 77 additions & 0 deletions libraries/dagster-hex/dagster_hex/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from dagster import (
AssetsDefinition,
asset,
AssetExecutionContext,
AssetMaterialization,
MetadataValue,
Output,
)
from dagster._annotations import experimental
from typing import Optional
from .resources import HexResource


@experimental
def build_hex_asset(
project_id: str,
resource: HexResource,
inputs: Optional[dict] = None,
update_cache: bool = False,
notifications: Optional[list] = None,
deps: Optional[list] = None,
tags: Optional[dict] = None,
) -> AssetsDefinition:
"""
Returns the AssetDefinition for a Hex Project

Args:
project_id: The Hex project id
resource: The HexResource
inputs: The inputs for the asset
update_cache: Whether to update the cache
notifications: The notifications for the asset
deps: The dependencies for the asset
tags: The tags for the asset
Returns:
AssetsDefinition: The AssetDefinition for the Hex Project
"""

project_name = resource.get_project(project_id)["title"]
metadata = resource.get_project_details(project_id)

@asset(
name=f"{project_name}__{project_id.replace('-', '_')}",
required_resource_keys={"hex"},
deps=deps,
metadata=metadata,
tags=tags,
kinds={"hex"},
)
def hex_asset(context: AssetExecutionContext):
output = context.resources.hex.run_and_poll(
project_id=project_id,
inputs=inputs,
update_cache=update_cache,
notifications=notifications,
)
asset_key = ["hex", project_name, project_id]
context.log_event(
AssetMaterialization(
asset_key,
description="Hex Project Details",
metadata={
"run_url": MetadataValue.url(output.run_response["runUrl"]),
"run_status_url": MetadataValue.url(
output.run_response["runStatusUrl"]
),
"trace_id": MetadataValue.text(output.run_response["traceId"]),
"run_id": MetadataValue.text(output.run_response["runId"]),
"elapsed_time": MetadataValue.int(
output.status_response["elapsedTime"]
),
},
)
)
yield Output(output)

return hex_asset
Loading