Project

General

Profile

Idea #18797 » arvados.retry.txt

pydoc output - Brett Smith, 11/10/2022 10:06 PM

 
1
Help on module arvados.retry in arvados:
2

    
3
NNAAMMEE
4
    arvados.retry - Utilities to retry operations.
5

    
6
DDEESSCCRRIIPPTTIIOONN
7
    The core of this module is `RetryLoop`, a utility class to retry operations
8
    that might  fail. It can distinguish between temporary and permanent failures;
9
    provide exponential backoff; and save a series of results.
10
    
11
    It also provides utility functions for common operations with `RetryLoop`:
12
    
13
    * `check_http_response_success` can be used as a `RetryLoop` `success_check`
14
      for HTTP response codes from the Arvados API server.
15
    * `retry_method` can decorate methods to provide a default `num_retries`
16
      keyword argument.
17

    
18
CCLLAASSSSEESS
19
    builtins.object
20
        RetryLoop
21
    
22
    class RReettrryyLLoooopp(builtins.object)
23
     |  RetryLoop(num_retries, success_check=<function RetryLoop.<lambda> at 0x7fcbac047790>, backoff_start=0, backoff_growth=2, save_results=1, max_wait=60)
24
     |  
25
     |  Coordinate limited retries of code.
26
     |  
27
     |  `RetryLoop` coordinates a loop that runs until it records a
28
     |  successful result or tries too many times, whichever comes first.
29
     |  Typical use looks like:
30
     |  
31
     |      loop = RetryLoop(num_retries=2)
32
     |      for tries_left in loop:
33
     |          try:
34
     |              result = do_something()
35
     |          except TemporaryError as error:
36
     |              log("error: {} ({} tries left)".format(error, tries_left))
37
     |          else:
38
     |              loop.save_result(result)
39
     |      if loop.success():
40
     |          return loop.last_result()
41
     |  
42
     |  Arguments:
43
     |  
44
     |  num_retries: int
45
     |  : The maximum number of times to retry the loop if it
46
     |    doesn't succeed.  This means the loop body could run at most
47
     |    `num_retries + 1` times.
48
     |  
49
     |  success_check: Callable
50
     |  : This is a function that will be called each
51
     |    time the loop saves a result.  The function should return
52
     |    `True` if the result indicates the code succeeded, `False` if it
53
     |    represents a permanent failure, and `None` if it represents a
54
     |    temporary failure.  If no function is provided, the loop will
55
     |    end after any result is saved.
56
     |  
57
     |  backoff_start: float
58
     |  : The number of seconds that must pass before the loop's second
59
     |    iteration.  Default 0, which disables all waiting.
60
     |  
61
     |  backoff_growth: float
62
     |  : The wait time multiplier after each iteration.
63
     |    Default 2 (i.e., double the wait time each time).
64
     |  
65
     |  save_results: int
66
     |  : Specify a number to store that many saved results from the loop.
67
     |    These are available through the `results` attribute, oldest first.
68
     |    Default 1.
69
     |  
70
     |  max_wait: float
71
     |  : Maximum number of seconds to wait between retries. Default 60.
72
     |  
73
     |  Methods defined here:
74
     |  
75
     |  ____iinniitt____(self, num_retries, success_check=<function RetryLoop.<lambda> at 0x7fcbac047790>, backoff_start=0, backoff_growth=2, save_results=1, max_wait=60)
76
     |      Initialize self.  See help(type(self)) for accurate signature.
77
     |  
78
     |  ____iitteerr____(self)
79
     |      Return an iterator of retries.
80
     |  
81
     |  ____nneexxtt____(self)
82
     |      Record a loop attempt.
83
     |      
84
     |      If the loop is still running, decrements the number of tries left and
85
     |      returns it. Otherwise, raises `StopIteration`.
86
     |  
87
     |  aatttteemmppttss(self)
88
     |      Return the number of results that have been saved.
89
     |      
90
     |      This count includes all kinds of results: success, permanent failure,
91
     |      and temporary failure.
92
     |  
93
     |  aatttteemmppttss__ssttrr(self)
94
     |      Return a human-friendly string counting saved results.
95
     |      
96
     |      !!! deprecated
97
     |          This method is deprecated. Use your favorite localization library
98
     |          instead.
99
     |      
100
     |          This is a demonstration notice for illustration. I do think we
101
     |          should probably deprecate this method, but not as part of this
102
     |          branch.
103
     |      
104
     |      This method returns '1 attempt' or 'N attempts', where the number
105
     |      in the string is the number of saved results.
106
     |  
107
     |  llaasstt__rreessuulltt(self)
108
     |      Return the most recent result the loop saved.
109
     |      
110
     |      Raises `arvados.errors.AssertionError` if called before any result has
111
     |      been saved.
112
     |  
113
     |  rruunnnniinngg(self)
114
     |      Return whether this loop is running.
115
     |      
116
     |      Returns `None` if the loop has never run, `True` if it is still running,
117
     |      or `False` if it has stopped—whether that's because it has saved a
118
     |      successful result, a permanent failure, or has run out of retries.
119
     |  
120
     |  ssaavvee__rreessuulltt(self, result)
121
     |      Record a loop result.
122
     |      
123
     |      Save the given result, and end the loop if it indicates
124
     |      success or permanent failure. See documentation for the `__init__`
125
     |      `success_check` argument to learn how that's indicated.
126
     |      
127
     |      Raises `arvados.errors.AssertionError` if called after the loop has
128
     |      already ended.
129
     |      
130
     |      Arguments:
131
     |      
132
     |      result: Any
133
     |      : The result from this loop attempt to check and save.
134
     |  
135
     |  ssuucccceessss(self)
136
     |      Return the loop's end state.
137
     |      
138
     |      Returns `True` if the loop recorded a successful result, `False` if it
139
     |      recorded permanent failure, or else `None`.
140
     |  
141
     |  ----------------------------------------------------------------------
142
     |  Data descriptors defined here:
143
     |  
144
     |  ____ddiicctt____
145
     |      dictionary for instance variables (if defined)
146
     |  
147
     |  ____wweeaakkrreeff____
148
     |      list of weak references to the object (if defined)
149

    
150
FFUUNNCCTTIIOONNSS
151
    cchheecckk__hhttttpp__rreessppoonnssee__ssuucccceessss(status_code)
152
        Convert a numeric HTTP status code to a loop control flag.
153
        
154
        This method takes a numeric HTTP status code and returns `True` if
155
        the code indicates success, `None` if it indicates temporary
156
        failure, and `False` otherwise.  You can use this as the
157
        `success_check` for a `RetryLoop` that queries the Arvados API server.
158
        Specifically:
159
        
160
        * Any 2xx result returns `True`.
161
        
162
        * A select few status codes, or any malformed responses, return `None`.
163
          422 Unprocessable Entity is in this category.  This may not meet the
164
          letter of the HTTP specification, but the Arvados API server will
165
          use it for various server-side problems like database connection
166
          errors.
167
        
168
        * Everything else returns `False`.  Note that this includes 1xx and
169
          3xx status codes.  They don't indicate success, and you can't
170
          retry those requests verbatim.
171
        
172
        Arguments:
173
        
174
        status_code: int
175
        : A numeric HTTP response code
176
    
177
    rreettrryy__mmeetthhoodd(orig_func)
178
        Provide a default value for a method's num_retries argument.
179
        
180
        This is a decorator for instance and class methods that accept a
181
        `num_retries` keyword argument, with a `None` default.  When the method
182
        is called without a value for `num_retries`, this decorator will set it
183
        from the `num_retries` attribute of the underlying instance or class.
184
        
185
        Arguments:
186
        
187
        orig_func: Callable
188
        : A class or instance method that accepts a `num_retries` keyword argument
189

    
190
FFIILLEE
191
    /home/brett/Curii/arvados/sdk/python/arvados/retry.py
192

    
(1-1/3)