🚧 🚧 🚧 🚧 🚧 🚧
Marvin is going to sleep for a bit, will update when back
🚧 🚧 🚧 🚧 🚧 🚧
Nate
10/15/2024, 11:23 PM
@Marvin hey write a task that computes fibonacci to n, no commentary. name task run w the input
m
Marvin
10/15/2024, 11:23 PM
Sure! Could you please specify if you are using Prefect 2.x or Prefect 3.x? This will help me provide you with the correct code snippet.
n
Nate
10/15/2024, 11:23 PM
@Marvin 3.x
m
Marvin
10/15/2024, 11:23 PM
Here's how you can define a task in Prefect 3.x to compute the Fibonacci sequence up to
n
and name the task run with the input:
Copy code
python
from prefect import flow, task
@task(task_run_name=lambda n: f"fibonacci-{n}")
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
@flow
def fibonacci_flow(n):
result = fibonacci(n)
print(f"Fibonacci of {n} is {result}")
# Example usage
fibonacci_flow(10)
This code defines a task that computes the Fibonacci number for a given
n
, and the task run is named dynamically based on the input value of
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.