Arun Kumar
04/09/2021, 10:12 AMsashank
04/09/2021, 10:38 AMimport datetime
from dagster import sensor, RunRequest, SkipReason
@solid(config_schema={"date": str})
def my_solid(context):
date = context.solid_config['date']
# You can now access date here
@pipeline
def my_pipeline():
my_solid()
@sensor(pipeline_name="my_pipeline")
def my_sensor(_)
if external_api_condition:
date = datetime.datetime.now().strftime("%Y/%m/%d")
yield RunRequest(run_config={"solids": {"my_solid": {"config": {"date": date}}}})
else:
yield SkipReason(skip_message="External API condition not met")
Arun Kumar
04/09/2021, 10:54 AMsashank
04/09/2021, 10:58 AMArun Kumar
04/09/2021, 11:07 AMtest_pipeline
pipeline using a sensor once everyday by passing the date partition through config, will dagit show the status of these runs in the partitions view of this pipeline? I guess it won't and thats's why I asked if sensors can use/generate PartitionSets
import dagster
import datetime
def run_config_for_date_partition(partition):
date = partition.value
return {"solids": {"query_telemetry_events": {"config": {"date": date}}}}
partition_sets = dagster.PartitionSetDefinition(
name="partition_set",
pipeline_name="test_pipeline",
partition_fn=dagster.utils.partitions.date_partition_range(
start=datetime.datetime(2021, 4, 09),
delta_range="days",
inclusive=True,
fmt="%Y-%m-%d-%H",
),
run_config_fn_for_partition=run_config_for_date_partition,
)
sashank
04/09/2021, 11:13 AM@sensor(pipeline_name="test_pipeline")
def my_sensor(_):
date_str = datetime.datetime.now().strftime("%Y-%m-%d-%H") # Make sure this format matches the partition set format
partition = partition_set.get_partition(name=date_str)
yield RunRequest(
run_config=partition_set.run_config_for_partition(partition),
tags=partition_set.tags_for_partition(partition),
)
date_partition_range
to create custom date range partition setsDagster Bot
04/09/2021, 11:14 AMsashank
04/09/2021, 11:15 AMPartitionSet.tags_for_partition
Dagster Bot
04/09/2021, 11:15 AMArun Kumar
04/09/2021, 11:20 AMtags_for_partition
in the docs.
Thanks a lot for the quick help and creating the tickets. I will try this out soonsashank
04/09/2021, 11:25 AM