Skip to content

Commit

Permalink
Try to clean up task runner noise (#14169)
Browse files Browse the repository at this point in the history
  • Loading branch information
cicdw committed Jun 20, 2024
1 parent 2497a09 commit 7bd3303
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 587 deletions.
84 changes: 0 additions & 84 deletions docs/3.0rc/develop/write-tasks/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -708,87 +708,3 @@ If you just need the result from a task, call the task from your flow. For most
the default behavior of calling a task directly and receiving a result is enough.
</Tip>

## Wait for

To create a dependency between two tasks that do not exchange data, but one needs to wait for the other to
finish, use the special [`wait_for`](/3.0rc/api-ref/prefect/tasks/#prefect.tasks.Task.submit) keyword argument:

```python
@task
def task_1():
pass

@task
def task_2():
pass

@flow
def my_flow():
x = task_1()

# task 2 will wait for task_1 to complete
y = task_2(wait_for=[x])
```

## Map

Prefect provides a `.map()` implementation that automatically creates a task run for each element of its
input data. Mapped tasks represent the computations of many individual children tasks.

The simplest Prefect map takes a task and applies it to each element of its inputs.

```python
from prefect import flow, task

@task
def print_nums(nums):
for n in nums:
print(n)

@task
def square_num(num):
return num**2

@flow
def map_flow(nums):
print_nums(nums)
squared_nums = square_num.map(nums)
print_nums(squared_nums)

map_flow([1,2,3,5,8,13])
```

Prefect also supports `unmapped` arguments, allowing you to pass static values that don't get mapped over.

```python
from prefect import flow, task

@task
def add_together(x, y):
return x + y

@flow
def sum_it(numbers, static_value):
futures = add_together.map(numbers, static_value)
return futures

sum_it([1, 2, 3], 5)
```

If your static argument is an iterable, wrap it with `unmapped` to tell Prefect to treat it
as a static value.

```python
from prefect import flow, task, unmapped

@task
def sum_plus(x, static_iterable):
return x + sum(static_iterable)

@flow
def sum_it(numbers, static_iterable):
futures = sum_plus.map(numbers, static_iterable)
return futures

sum_it([4, 5, 6], unmapped([1, 2, 3]))
```
266 changes: 0 additions & 266 deletions docs/3.0rc/develop/write-tasks/upstream-dependencies.mdx

This file was deleted.

Loading

0 comments on commit 7bd3303

Please sign in to comment.