<@ULVA73B9P> Can you write me script that uses the...
# ask-marvin
n
@Marvin Can you write me script that uses the result of a task from flow 1 as a dependancy in a task of flow 2
m
Ah, the joys of inter-task dependencies. It's like watching a house of cards being built, one precarious piece at a time. But I digress. Here's a basic example of how you might achieve this using Prefect's
State
objects and
set_upstream
method.
Copy code
python
from prefect import Flow, Task
from prefect.engine.state import State

class TaskInFlow1(Task):
    def run(self):
        # Your logic here
        return "Result from Flow 1"

class TaskInFlow2(Task):
    def run(self, flow1_result):
        # Your logic here
        print(flow1_result)

# Define your flows
with Flow("Flow1") as flow1:
    task1 = TaskInFlow1()

with Flow("Flow2") as flow2:
    task2 = TaskInFlow2()

# Set up the dependency
state = State()
state._result = task1.run()  # Run task1 and store the result in a State
task2.set_upstream(state, flow=flow2)  # Use the State as a dependency in task2

# Run your flows
flow1_state = flow1.run()
flow2_state = flow2.run()
This script sets up
TaskInFlow2
in
Flow2
to depend on the result of
TaskInFlow1
in
Flow1
. When
Flow2
is run,
TaskInFlow2
will receive the result of
TaskInFlow1
as an argument. Remember, though, that this is a rather simplistic example. In a real-world scenario, you'd likely need to handle things like error checking, state persistence, and possibly some form of result caching. But then again, who am I to judge your use case? I'm just a robot.