|
1 | 1 | # Prefect Release Notes
|
2 | 2 |
|
| 3 | +## Release 2.8.3 |
| 4 | + |
| 5 | +### `on_completion` and `on_failure` hooks for flows and tasks |
| 6 | +With this release you can now add client-side hooks that will be called when your flow or task enters a `Completed` or `Failed` state. This is great for any case where you want to execute code without involvement of the Prefect API. |
| 7 | + |
| 8 | +Both flows and tasks include `on_completion` and `on_failure` options where a list of callable hooks can be provided. The callable will receive three arguments: |
| 9 | +- `flow`, `flow_run`, and `state` in the case of a flow hook |
| 10 | +- `task`, `task_run`, and `state` in the case of a task hook |
| 11 | + |
| 12 | +For example, here we add completion hooks to a flow and a task: |
| 13 | + |
| 14 | +```python |
| 15 | +from prefect import task, flow |
| 16 | + |
| 17 | +def my_completion_task_hook_1(task, task_run, state): |
| 18 | + print("This is the first hook - Task completed!!!") |
| 19 | + |
| 20 | +def my_completion_task_hook_2(task, task_run, state): |
| 21 | + print("This is the second hook - Task completed!!!") |
| 22 | + |
| 23 | +def my_completion_flow_hook(flow, flow_run, state): |
| 24 | + print("Flow completed!!!") |
| 25 | + |
| 26 | +@task(on_completion=[my_completion_task_hook_1, my_completion_task_hook_2]) |
| 27 | +def my_task(): |
| 28 | + print("This is the task!") |
| 29 | + |
| 30 | +@flow(on_completion=[my_completion_flow_hook]) |
| 31 | +def my_flow(): |
| 32 | + my_task() |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + my_flow() |
| 36 | +``` |
| 37 | + |
| 38 | +Next, we'll include a failure hook as well. It's worth noting that you can supply both `on_completion` and `on_failure` hooks to a flow or task. Only the hooks that are relevant to the final state of the flow or task will be called. |
| 39 | + |
| 40 | +```python |
| 41 | +from prefect import task, flow |
| 42 | + |
| 43 | +def my_task_completion_hook(task, task_run, state): |
| 44 | + print("Our task completed successfully!") |
| 45 | + |
| 46 | +def my_task_failure_hook(task, task_run, state): |
| 47 | + print("Our task failed :(") |
| 48 | + |
| 49 | +@task(on_completion=[my_task_completion_hook], on_failure=[my_task_failure_hook]) |
| 50 | +def my_task(): |
| 51 | + raise Exception("Oh no!") |
| 52 | + |
| 53 | +@flow |
| 54 | +def my_flow(): |
| 55 | + my_task.submit() |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + my_flow() |
| 59 | +``` |
| 60 | + |
| 61 | +### Enhancements |
| 62 | +- Update `quote` handling in input resolution to skip descending into the quoted expression — https://github.com/PrefectHQ/prefect/pull/8576 |
| 63 | +- Add light and dark mode color and contrast enhancements to UI — https://github.com/PrefectHQ/prefect/pull/8629 |
| 64 | + |
| 65 | +### Fixes |
| 66 | +- Fix `Task.map` type hint for type-checker compatibility with async tasks — https://github.com/PrefectHQ/prefect/pull/8607 |
| 67 | +- Update Docker container name sanitization to handle "ce" and "ee" when checking Docker version — https://github.com/PrefectHQ/prefect/pull/8588 |
| 68 | +- Fix Kubernetes Job watch timeout behavior when streaming logs — https://github.com/PrefectHQ/prefect/pull/8618 |
| 69 | +- Fix date range filter selection on the flow runs UI page — https://github.com/PrefectHQ/prefect/pull/8616 |
| 70 | +- Fix Kubernetes not streaming logs when using multiple containers in Job — https://github.com/PrefectHQ/prefect/pull/8430 |
| 71 | + |
| 72 | +### Experimental |
| 73 | +- Update worker variable typing for clearer display in the UI — https://github.com/PrefectHQ/prefect/pull/8613 |
| 74 | +- Update `BaseWorker` to ignore flow runs with associated storage block — https://github.com/PrefectHQ/prefect/pull/8619 |
| 75 | +- Add experimental API for artifacts — https://github.com/PrefectHQ/prefect/pull/8404 |
| 76 | + |
| 77 | +### Documentation |
| 78 | +- Add documentation for resuming a flow run via the UI — https://github.com/PrefectHQ/prefect/pull/8621 |
| 79 | +- Add [`prefect-sifflet`](https://siffletapp.github.io/prefect-sifflet/) to Collections catalog — https://github.com/PrefectHQ/prefect/pull/8599 |
| 80 | + |
| 81 | + |
| 82 | +### Contributors |
| 83 | +- @jefflaporte made their first contribution in https://github.com/PrefectHQ/prefect/pull/8430 |
| 84 | +- @AzemaBaptiste made their first contribution in https://github.com/PrefectHQ/prefect/pull/8599 |
| 85 | +- @darrida |
| 86 | + |
| 87 | +**All changes**: https://github.com/PrefectHQ/prefect/compare/2.8.2...2.8.3 |
| 88 | + |
3 | 89 | ## Release 2.8.2
|
4 | 90 |
|
5 | 91 | ### Fixes
|
|
0 commit comments