MCPcopy Create free account
hub / github.com/ceph/ceph / retry

Function retry

src/ceph-node-proxy/ceph_node_proxy/util.py:152–170  ·  view source on GitHub ↗
(
    exceptions: Any = Exception, retries: int = 20, delay: int = 1
)

Source from the content-addressed store, hash-verified

150
151
152def retry(
153 exceptions: Any = Exception, retries: int = 20, delay: int = 1
154) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
155 def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
156 def _retry(*args: Any, **kwargs: Any) -> Any:
157 _tries = retries
158 while _tries > 1:
159 try:
160 logger.debug("{} {} attempt(s) left.".format(f, _tries - 1))
161 return f(*args, **kwargs)
162 except exceptions:
163 time.sleep(delay)
164 _tries -= 1
165 logger.warning("{} has failed after {} tries".format(f, retries))
166 return f(*args, **kwargs)
167
168 return _retry
169
170 return decorator
171
172
173def http_req(

Callers 2

startMethod · 0.50
finishMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected