Hi, I have trouble understanding the @task concept...
# prefect-getting-started
f
Hi, I have trouble understanding the @task concept.. When a task fails, I want the flow to continue. Also, when I click the "Retry" button on a completed flow, why are all it's task run again? It clearly states """This will retry flow run important-viper. Any task runs in a failed, cancelled or crashed state will be run again.""", so completed tasks should be skipped, right? My usecase is that sometimes, a task might raise an exception and I don't want to redo all tasks again and I want prefect to keep track where it should pick up again. Are my expectations valid?
k
I'm not an expert by any means but a task is just a single component of a flow. A flow by definition is a collection of tasks. So if it states "This will retry flow run important-viper", it is stating it will rerun the entire flow, including all tasks within the flow. If you want to retry a task specifically, I would define your tasks with something like this:
Copy code
@task(retries=3, retry_delay_seconds=10, timeout_seconds=600)
These parameters say that if a task fails, it will be reran a maximum of 3 times, with a 10 second delay in between. timeout_seconds defines how long a task can run before it gets given a status of "failed". So if any of these tasks take over 600 seconds, they will be killed and retried if they have not been retried the maximum amount of times. If a task fails more than 3 times in a row, you more than likely should restructure your code to fail less often. As far as your usecase, if I am understanding correctly, a task raising an exception is not a "fail". Catching errors with exceptions is used explicitly for this purpose, catching errors and not making your code fail. You can have 10 execptions raised and still have a status of "successfully ran" because it did in fact run successfully. You caught the errors as exceptions, allowing your code to continue successfully. If you want the code to fail and retry you would need to remove the exceptions so that task actually fails, or write some logic to handle your exceptions differently.