Advertisement
Guest User

Untitled

a guest
Mar 31st, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from typing import List
  2.  
  3. from prefect import Flow, task
  4.  
  5.  
  6. @task(checkpoint=False)
  7. def task_1() -> List[int]:
  8.     return list(range(15))
  9.  
  10.  
  11. @task(checkpoint=False)
  12. def task_2(input: int) -> int:
  13.     return input + 1
  14.  
  15.  
  16. @task(checkpoint=False)
  17. def task_3(list_of_ints: List[int]) -> str:
  18.     print(f"---------------- len: {len(list_of_ints)} -----------------")
  19.     return "task_3 done"
  20.  
  21.  
  22. @task(checkpoint=False)
  23. def task_4(input: int) -> int:
  24.     return input + 2
  25.  
  26.  
  27. with Flow("Flow") as flow:
  28.     list_of_ints_1 = task_1()
  29.     list_of_ints_2 = task_2.map(list_of_ints_1)
  30.     str_output = task_3(list_of_ints_2)
  31.     task_4.map(list_of_ints_2, upstream_tasks=[str_output])
  32.  
  33. status = flow.run()
  34. flow.visualize(status, filename="./flow", format="svg")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement