Hey Y'all I'm wondering if there is a way to point...
# announcements
j
Hey Y'all I'm wondering if there is a way to point a
ScheduleDefinition
's
should_execute
filter to another pipeline having completed. I'm wondering if there is a way to set dependencies like Pipeline B executes at scheduled time if and only if the last run of Pipeline A successfully ran.
s
Hey @John Mav, this is definitely possible. The
should_execute
function is passed a
context
which an instance of
ScheduleExecutionContext
. On this we can access
context.instance
which lets us query the run storage using the
get_runs
method
To do what you’re describing:
Copy code
def should_execute(context):
    run_filter = PipelineRunsFilter(pipeline_name="Pipeline A")
    runs = context.instance.get_runs(run_filter, limit=1)
    if not len(runs):
        return False

    latest_run = runs[0]
    if latest_run.status == PipelineRunStatus.SUCCESS:
        return True

    return False
Does this work for you?
j
Oh this is amazing! Thank you @sashank 😄