Hello all, I see that I can set up retry logic wit...
# ask-community
m
Hello all, I see that I can set up retry logic with
Copy code
@task(max_retries=3)
but how can I set up the retry logic if I am not setting up tasks with the functional API? I do not see anything in the docs that explains. Thank you in advance!
z
Hi @Matthew Blau Any
Task
class takes a
max_retries
argument, if you pass
max_retries
to
super().init
, your custom task will use this value
Copy code
class CustomTask(Task):
  def __init__(self, my_arg, **kwargs):
    self.prop = my_arg
    super().__init__(**kwargs)
Copy code
my_custom_task = CustomTask(my_arg='foo', kwargs={'max_retries':100})
m
@Zach Angell so in my case I have a flow that looks like
with Flow(name="integration",          state_handlers=[slack_notifier],) as flow:    start_container = start(container_id=container)    code = status_code(container_id=container, upstream_tasks=[start_container]) collect_logs = logs(container_id=container, upstream_tasks=[code])
Copy code
so what you're saying is that I can pass in {'max_retires':3} to the start_container task?
k
I think Zach’s approach is when creating your Task by inheriting the Task class. Can I see the definition of the
start_container
task you have?
upvote 1
e
Copy code
start = StartContainer(max_retries=3)
with Flow(name="integration", state_handlers=[slack_notifier],) as flow:
    start_container = start(container_id=container)    
    code = status_code(container_id=container, upstream_tasks=[start_container]) 
    collect_logs = logs(container_id=container, upstream_tasks=[code])
tasks need to be first initialized, and then called. Assuming you got your example from: https://docs.prefect.io/core/examples/functional_docker.html btw 😅
upvote 2
k
I see. Thanks for that @emre!
m
@emre yep! I got my example from there