Skip to content

Instantly share code, notes, and snippets.

@zanieb
Created December 8, 2022 16:17
Show Gist options
  • Save zanieb/61facb93fa4e0cfe7e6fc45997b1f4ae to your computer and use it in GitHub Desktop.
Save zanieb/61facb93fa4e0cfe7e6fc45997b1f4ae to your computer and use it in GitHub Desktop.
from prefect import Flow, task, Parameter
@task
def foo():
print("foo")
@task
def bar():
print("bar")
@task
def plusone(x):
return x + 1
def foobar():
foo()
bar()
def do_some_math(start_at):
# Parameters can be passed to tasks
result = plusone(start_at)
# Logic cannot be performed unless in a task e.g.
# if result > 2: ... not allowed
return result
with Flow("example") as flow:
start_at = Parameter("start_at", default=0)
foobar()
math_result = do_some_math(start_at)
# Tasks can be called directly in the flow still
plusone(math_result)
flow.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment