Tobias Macey
02/13/2024, 8:15 PMScout
02/13/2024, 8:15 PMAssetSpec
and external_assets_from_specs
if you're dealing with an asset that is not materialized by Dagster but you want to track it within Dagster's asset catalog.
2. Create a Sensor: You would then define a sensor using the @sensor
decorator. This sensor would be responsible for checking the external system for new partitions of the asset and triggering a run when it detects changes.
3. Trigger a Job or Op: When the sensor detects a new partition, it should trigger a job or op that processes the new partition. This can be done by returning a RunRequest
from the sensor function, which includes the necessary run configuration for the job or op that processes the asset.
4. Use the Python API: If you need to backfill metadata or report events for the external asset, you can use the report_runless_asset_event
method on the DagsterInstance
to insert events directly from Dagster's Python API.
Here is a simplified example based on the documentation's guidance:
python
from dagster import sensor, RunRequest, DagsterInstance, AssetMaterialization
# Assume 'my_external_asset_op' is an op that processes the external asset
from my_project import my_external_asset_op
@sensor(job=my_external_asset_op)
def my_external_asset_sensor(context):
# Logic to check for new partitions in the external system
new_partitions = check_for_new_partitions()
if new_partitions:
for partition in new_partitions:
# Trigger a run for each new partition
yield RunRequest(
run_key=partition, # Unique identifier for the run
run_config={
# Include necessary run configuration for processing the partition
},
)
# Function to check for new partitions in the external system
def check_for_new_partitions():
# Implement logic to detect new partitions
pass
# Assuming you have a DagsterInstance
instance = DagsterInstance.get()
# Report an asset event without a run
instance.report_runless_asset_event(
AssetMaterialization(
"external_asset_partition", metadata={"partition": "new_partition"}
)
)
Please note that this is a high-level exaScout
02/13/2024, 8:16 PM