Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/dapr-ext-workflow/dapr/ext/workflow/retry_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
Args:
first_retry_interval(timedelta): The retry interval to use for the first retry attempt.
max_number_of_attempts(int): The maximum number of retry attempts.
Use ``-1`` for infinite retries.
backoff_coefficient(Optional[float]): The backoff coefficient to use for calculating
the next retry interval.
max_retry_interval(Optional[timedelta]): The maximum retry interval to use for any
Expand All @@ -50,8 +51,8 @@ def __init__(
# validate inputs
if first_retry_interval < timedelta(seconds=0):
raise ValueError('first_retry_interval must be >= 0')
if max_number_of_attempts < 1:
raise ValueError('max_number_of_attempts must be >= 1')
if max_number_of_attempts == 0 or max_number_of_attempts < -1:
raise ValueError('max_number_of_attempts must be >= 1 or -1 for infinite retries')
if backoff_coefficient is not None and backoff_coefficient < 1:
raise ValueError('backoff_coefficient must be >= 1')
if max_retry_interval is not None and max_retry_interval < timedelta(seconds=0):
Expand Down
35 changes: 35 additions & 0 deletions ext/dapr-ext-workflow/tests/test_retry_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

"""
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import unittest
from datetime import timedelta

from dapr.ext.workflow.retry_policy import RetryPolicy


class RetryPolicyTests(unittest.TestCase):
def test_allow_infinite_max_number_of_attempts(self):
retry_policy = RetryPolicy(
first_retry_interval=timedelta(seconds=1), max_number_of_attempts=-1
)

self.assertEqual(-1, retry_policy.max_number_of_attempts)

def test_reject_invalid_max_number_of_attempts(self):
with self.assertRaises(ValueError):
RetryPolicy(first_retry_interval=timedelta(seconds=1), max_number_of_attempts=0)

with self.assertRaises(ValueError):
RetryPolicy(first_retry_interval=timedelta(seconds=1), max_number_of_attempts=-2)