Hi guys, Is there a way to import a function form ...
# ask-community
a
Hi guys, Is there a way to import a function form another file as a task? I was trying something like this:
Copy code
from tasks.date import get_start_date
@task(name='Generate start date', retries=2, retry_delay_seconds=10)(get_start_date)
It fails with `RuntimeError: Tasks cannot be run outside of a flow. To call the underlying task function outside of a flow use
task.fn()
.` Thanks!
1
r
Hi Alexandru, would something like this do what you need?
Copy code
from prefect import flow, task
from tasks.date import get_start_date

get_start_date_task = task(get_start_date, name='Generate start date', retries=2, retry_delay_seconds=10)

# you can now call get_start_date_task inside a flow

@flow
def my_flow():
    start_date = get_start_date_task()
a
Yes, works beautifully! Thanks, Ryan!
😀 1
👍 1