Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tweaks to task retry docs #9575

Merged
merged 4 commits into from
May 23, 2023
Merged

Additional tweaks to task retry docs #9575

merged 4 commits into from
May 23, 2023

Conversation

abrookins
Copy link
Collaborator

Clean up the docs for task retries.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • This pull request includes tests or only affects documentation.
  • This pull request includes a label categorizing the change e.g. fix, feature, enhancement, docs.

@abrookins abrookins added the docs label May 15, 2023
@abrookins abrookins requested a review from a team as a code owner May 15, 2023 18:19
@netlify
Copy link

netlify bot commented May 15, 2023

Deploy Preview for prefect-docs-preview ready!

Name Link
🔨 Latest commit 0a188e3
🔍 Latest deploy log https://app.netlify.com/sites/prefect-docs-preview/deploys/646b97d25032110008c2bb05
😎 Deploy Preview https://deploy-preview-9575--prefect-docs-preview.netlify.app/concepts/tasks
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@billpalombi billpalombi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tasks must

@@ -204,29 +204,80 @@ def my_flow():

## Retries

Prefect tasks can automatically retry on failure. To enable retries, pass `retries` and `retry_delay_seconds` parameters to your task.
Prefect can automatically retry tasks on failure. In Prefect, a task _fails_
if it returns a value that is not a `State` object, or if it raises an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if it returns a value that is not a `State` object, or if it raises an
if its python function raises an exception or, uncommonly, returns a value that is not a `State` object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billpalombi Isn't a task a function? 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I see what you mean now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave out the State part for now because it doesn't make sense and I don't understand what would cause that. (It can't be that the user-defined function returned an object other than a State...).

Prefect tasks can automatically retry on failure. To enable retries, pass `retries` and `retry_delay_seconds` parameters to your task.
Prefect can automatically retry tasks on failure. In Prefect, a task _fails_
if it returns a value that is not a `State` object, or if it raises an
exception.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exception.

from random import randint
from prefect import task

@task(retries=3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, right? A task must be in a flow.

Copy link
Contributor

@billpalombi billpalombi May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeError: Tasks cannot be run outside of a flow. To call the underlying task function outside of a flow use task.fn()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the definition of a task. You have to call or submit tasks from a flow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, you didn't intend for this to be a runnable example. Most (all?) of the other code examples that we include in the docs are runnable, so including a code snippet that can't be run in isolation is a departure from the norm. If we are going to include an example that isn't runnable in isolation, I think we should remove the import statements, so it doesn't look like its code meant to be copied, pasted, and run in isolation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also might want to explicitly call out thats its just a definition, and must be called from a flow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. I see. The other examples in this section aren't runnable, so I didn't even notice! I'll adapt this to have a flow that calls it.

Copy link
Contributor

@billpalombi billpalombi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you!

@abrookins abrookins merged commit 4c56a9a into main May 23, 2023
@abrookins abrookins deleted the more-retry-tweaks branch May 23, 2023 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants