예제 #1
0
 def test_retry_once(self):
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=self.errback, interval_max=14,
         )
     assert self.index == 1
     # no errback
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=None, interval_max=14,
         )
예제 #2
0
 def test_retry_once(self):
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=self.errback, interval_max=14,
         )
     assert self.index == 1
     # no errback
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=None, interval_max=14,
         )
예제 #3
0
 def test_retry_once(self):
     with self.assertRaises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=self.errback, interval_max=14,
         )
     self.assertEqual(self.index, 1)
     # no errback
     with self.assertRaises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=1, errback=None, interval_max=14,
         )
예제 #4
0
 def test_retry_zero(self, sleepdeprived):
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=0, errback=self.errback, interval_max=14,
         )
     assert self.index == 0
     # no errback
     with pytest.raises(self.Predicate):
         retry_over_time(
             self.myfun, self.Predicate,
             max_retries=0, errback=None, interval_max=14,
         )
예제 #5
0
    def test_retry_timeout(self):

        with pytest.raises(self.Predicate):
            retry_over_time(
                self.myfun, self.Predicate,
                errback=self.errback, interval_max=14, timeout=1
            )
        assert self.index == 1

        # no errback
        with pytest.raises(self.Predicate):
            retry_over_time(
                self.myfun, self.Predicate,
                errback=None, timeout=1,
            )
예제 #6
0
    def test_retry_timeout(self):

        with pytest.raises(self.Predicate):
            retry_over_time(
                self.myfun, self.Predicate,
                errback=self.errback, interval_max=14, timeout=1
            )
        assert self.index == 1

        # no errback
        with pytest.raises(self.Predicate):
            retry_over_time(
                self.myfun, self.Predicate,
                errback=None, timeout=1,
            )
예제 #7
0
 def ensure(self, fun, args, **policy):
     retry_policy = dict(self.retry_policy, **policy)
     max_retries = retry_policy.get('max_retries')
     return retry_over_time(
         fun, self.connection_errors, args, {},
         partial(self.on_connection_error, max_retries),
         **retry_policy)
예제 #8
0
    def test_retry_always(self):
        Predicate = self.Predicate

        class Fun(object):

            def __init__(self):
                self.calls = 0

            def __call__(self, *args, **kwargs):
                try:
                    if self.calls >= 10:
                        return 42
                    raise Predicate()
                finally:
                    self.calls += 1
        fun = Fun()

        self.assertEqual(
            retry_over_time(
                fun, self.Predicate,
                max_retries=0, errback=None, interval_max=14,
            ),
            42,
        )
        self.assertEqual(fun.calls, 11)
예제 #9
0
파일: redis.py 프로젝트: songminger/celery
 def ensure(self, fun, args, **policy):
     retry_policy = dict(self.retry_policy, **policy)
     max_retries = retry_policy.get('max_retries')
     return retry_over_time(
         fun, self.connection_errors, args, {},
         partial(self.on_connection_error, max_retries),
         **retry_policy)
예제 #10
0
 def test_simple(self):
     prev_count, utils.count = utils.count, Mock()
     try:
         utils.count.return_value = list(range(1))
         x = retry_over_time(self.myfun, self.Predicate,
                             errback=None, interval_max=14)
         assert x is None
         utils.count.return_value = list(range(10))
         cb = Mock()
         x = retry_over_time(self.myfun, self.Predicate,
                             errback=self.errback, callback=cb,
                             interval_max=14)
         assert x == 42
         assert self.index == 9
         cb.assert_called_with()
     finally:
         utils.count = prev_count
예제 #11
0
 def test_simple(self):
     prev_count, utils.count = utils.count, Mock()
     try:
         utils.count.return_value = list(range(1))
         x = retry_over_time(self.myfun, self.Predicate,
                             errback=None, interval_max=14)
         assert x is None
         utils.count.return_value = list(range(10))
         cb = Mock()
         x = retry_over_time(self.myfun, self.Predicate,
                             errback=self.errback, callback=cb,
                             interval_max=14)
         assert x == 42
         assert self.index == 9
         cb.assert_called_with()
     finally:
         utils.count = prev_count
예제 #12
0
파일: signal.py 프로젝트: zhengjiali/celery
                    def _try_receiver_over_time(*args, **kwargs):
                        def on_error(exc, intervals, retries):
                            interval = next(intervals)
                            err_msg = RECEIVER_RETRY_ERROR % \
                                {'receiver': retry_fun,
                                 'when': humanize_seconds(interval, 'in', ' ')}
                            logger.error(err_msg)
                            return interval

                        return retry_over_time(retry_fun, Exception, args,
                                               kwargs, on_error)
예제 #13
0
파일: signal.py 프로젝트: atombrella/celery
                    def _try_receiver_over_time(*args, **kwargs):
                        def on_error(exc, intervals, retries):
                            interval = next(intervals)
                            err_msg = RECEIVER_RETRY_ERROR % \
                                {'receiver': retry_fun,
                                 'when': humanize_seconds(interval, 'in', ' ')}
                            logger.error(err_msg)
                            return interval

                        return retry_over_time(retry_fun, Exception, args,
                                               kwargs, on_error)
예제 #14
0
                    def _try_receiver_over_time(*args, **kwargs):
                        def on_error(exc, intervals, retries):
                            interval = next(intervals)
                            err_msg = RECEIVER_RETRY_ERROR % {
                                "receiver": retry_fun,
                                "when": humanize_seconds(interval, "in", " "),
                            }
                            logger.error(err_msg)
                            return interval

                        return retry_over_time(retry_fun, Exception, args,
                                               kwargs, on_error)
예제 #15
0
    def test_retry_always(self):
        Predicate = self.Predicate

        class Fun(object):

            def __init__(self):
                self.calls = 0

            def __call__(self, *args, **kwargs):
                try:
                    if self.calls >= 10:
                        return 42
                    raise Predicate()
                finally:
                    self.calls += 1
        fun = Fun()

        assert retry_over_time(
            fun, self.Predicate,
            max_retries=None, errback=None, interval_max=14) == 42
        assert fun.calls == 11
예제 #16
0
 def retry_over_time(self, *args, **kwargs):
     return retry_over_time(*args, **kwargs)
예제 #17
0
 def retry_over_time(self, *args, **kwargs):
     return retry_over_time(*args, **kwargs)