@@ -155,10 +155,12 @@ def _parse_retry_pattern(self):
155
155
try :
156
156
# as json can't have integers as keys and the field is stored
157
157
# as json, convert back to int
158
- retry_pattern = {
159
- int (try_count ): postpone_seconds
160
- for try_count , postpone_seconds in self .retry_pattern .items ()
161
- }
158
+ retry_pattern = {}
159
+ for try_count , postpone_value in self .retry_pattern .items ():
160
+ if isinstance (postpone_value , int ):
161
+ retry_pattern [int (try_count )] = postpone_value
162
+ else :
163
+ retry_pattern [int (try_count )] = tuple (postpone_value )
162
164
except ValueError :
163
165
_logger .error (
164
166
"Invalid retry pattern for job function %s,"
@@ -187,8 +189,9 @@ def job_config(self, name):
187
189
def _retry_pattern_format_error_message (self ):
188
190
return _ (
189
191
"Unexpected format of Retry Pattern for {}.\n "
190
- "Example of valid format:\n "
191
- "{{1: 300, 5: 600, 10: 1200, 15: 3000}}"
192
+ "Example of valid formats:\n "
193
+ "{{1: 300, 5: 600, 10: 1200, 15: 3000}}\n "
194
+ "{{1: (1, 10), 5: (11, 20), 10: (21, 30), 15: (100, 300)}}"
192
195
).format (self .name )
193
196
194
197
@api .constrains ("retry_pattern" )
@@ -201,12 +204,20 @@ def _check_retry_pattern(self):
201
204
all_values = list (retry_pattern ) + list (retry_pattern .values ())
202
205
for value in all_values :
203
206
try :
204
- int (value )
207
+ self . _retry_value_type_check (value )
205
208
except ValueError as ex :
206
209
raise exceptions .UserError (
207
210
record ._retry_pattern_format_error_message ()
208
211
) from ex
209
212
213
+ def _retry_value_type_check (self , value ):
214
+ if isinstance (value , (tuple , list )):
215
+ if len (value ) != 2 :
216
+ raise ValueError
217
+ [self ._retry_value_type_check (element ) for element in value ]
218
+ return
219
+ int (value )
220
+
210
221
def _related_action_format_error_message (self ):
211
222
return _ (
212
223
"Unexpected format of Related Action for {}.\n "
0 commit comments