File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 51
51
"""
52
52
53
53
CONNECTION_RETRY_STEP = """\
54
- Trying again {when}...\
54
+ Trying again {when}... ({retries}/{max_retries}) \
55
55
"""
56
56
57
57
CONNECTION_ERROR = """\
@@ -421,8 +421,11 @@ def ensure_connected(self, conn):
421
421
def _error_handler (exc , interval , next_step = CONNECTION_RETRY_STEP ):
422
422
if getattr (conn , 'alt' , None ) and interval == 0 :
423
423
next_step = CONNECTION_FAILOVER
424
- error (CONNECTION_ERROR , conn .as_uri (), exc ,
425
- next_step .format (when = humanize_seconds (interval , 'in' , ' ' )))
424
+ next_step = next_step .format (
425
+ when = humanize_seconds (interval , 'in' , ' ' ),
426
+ retries = int (interval / 2 ),
427
+ max_retries = self .app .conf .broker_connection_max_retries )
428
+ error (CONNECTION_ERROR , conn .as_uri (), exc , next_step )
426
429
427
430
# remember that the connection is lazy, it won't establish
428
431
# until needed.
Original file line number Diff line number Diff line change @@ -264,6 +264,22 @@ def test_connect_error_handler(self):
264
264
errback = conn .ensure_connection .call_args [0 ][0 ]
265
265
errback (Mock (), 0 )
266
266
267
+ @patch ('celery.worker.consumer.consumer.error' )
268
+ def test_connect_error_handler_progress (self , error ):
269
+ self .app .conf .broker_connection_retry = True
270
+ self .app .conf .broker_connection_max_retries = 3
271
+ self .app ._connection = _amqp_connection ()
272
+ conn = self .app ._connection .return_value
273
+ c = self .get_consumer ()
274
+ assert c .connect ()
275
+ errback = conn .ensure_connection .call_args [0 ][0 ]
276
+ errback (Mock (), 2 )
277
+ assert error .call_args [0 ][3 ] == 'Trying again in 2.00 seconds... (1/3)'
278
+ errback (Mock (), 4 )
279
+ assert error .call_args [0 ][3 ] == 'Trying again in 4.00 seconds... (2/3)'
280
+ errback (Mock (), 6 )
281
+ assert error .call_args [0 ][3 ] == 'Trying again in 6.00 seconds... (3/3)'
282
+
267
283
268
284
class test_Heart :
269
285
You can’t perform that action at this time.
0 commit comments