https://prefect.io logo
Title
m

Maikel Penz

11/07/2019, 3:13 AM
Hey.. question about
task retries
. Shouldn't the code below
retry
only every 30 seconds ? When I run it the output goes from 1 to 40 in less than a second and finishes. I expected it would take 30(seconds) x 40 runs to finish (as per my
if loop_count == 40:
to stop)
from prefect import Flow, task, context
from prefect.engine.signals import LOOP
import datetime
import time

@task(max_retries=50, retry_delay=datetime.timedelta(seconds=30))
def test_retry():
    loop_count = context.get("task_loop_count", {})
    print(loop_count)

    if loop_count == 40:
        return "finished"

    raise LOOP(message="Next run")

with Flow("test-pipeline") as flow:
    test_retry()

flow.run()
c

Chris White

11/07/2019, 3:18 AM
Hi @Maikel Penz - retries only occur whenever a task fails, and it looks like this task should run smoothly every time
m

Maikel Penz

11/07/2019, 3:19 AM
right.. I thought that using
raise LOOP(message="Next run")
would force the next retry
c

Chris White

11/07/2019, 3:21 AM
ah gotcha - while that is technically an exception, it carries with it an underlying Prefect state signaling what state the task should transition to. A more obvious example would be the
SUCCESS
signal, which forceably transitions the task to a
Success
state
m

Maikel Penz

11/07/2019, 3:23 AM
it makes sense.. thanks Chris !
c

Chris White

11/07/2019, 3:23 AM
anytime!