1
# Copyright 2014-2015 Canonical Limited.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
16
# Copyright 2014 Canonical Ltd.
19
# Edward Hope-Morley <opentastic@gmail.com>
24
from charmhelpers.core.hookenv import (
30
def retry_on_exception(num_retries, base_delay=0, exc_type=Exception):
31
"""If the decorated function raises exception exc_type, allow num_retries
32
retry attempts before raise the exception.
34
def _retry_on_exception_inner_1(f):
35
def _retry_on_exception_inner_2(*args, **kwargs):
40
return f(*args, **kwargs)
45
delay = base_delay * multiplier
47
log("Retrying '%s' %d more times (delay=%s)" %
48
(f.__name__, retries, delay), level=INFO)
53
return _retry_on_exception_inner_2
55
return _retry_on_exception_inner_1