Skip to content

Commit 339c596

Browse files
doc/development: document Strategy's @never_retry decorator
Signed-off-by: Bastian Krause <[email protected]>
1 parent f69dca4 commit 339c596

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

doc/development.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Start by creating a strategy skeleton:
226226
import attr
227227

228228
from labgrid.step import step
229-
from labgrid.strategy import Strategy, StrategyError
229+
from labgrid.strategy import Strategy, StrategyError, never_retry
230230
from labgrid.factory import target_factory
231231

232232
class Status(enum.Enum):
@@ -239,6 +239,7 @@ Start by creating a strategy skeleton:
239239

240240
status = attr.ib(default=Status.unknown)
241241

242+
@never_retry
242243
@step()
243244
def transition(self, status, *, step):
244245
if not isinstance(status, Status):
@@ -262,9 +263,21 @@ It is possible to reference drivers via their protocol, e.g.
262263
Note that drivers which implement multiple protocols must not be referenced
263264
multiple times via different protocols.
264265
The ``Status`` class needs to be extended to cover the states of your strategy,
265-
then for each state an ``elif`` entry in the transition function needs to be
266+
then for each state an ``elif`` entry in the ``transition()`` method needs to be
266267
added.
267268

269+
.. note::
270+
Since infrastructure failures or broken strategies typically cannot recover,
271+
it makes little sense to continue operating with such a strategy after an
272+
error has occurred.
273+
To clearly mark a strategy as unusable after failure (and to avoid cascading
274+
errors in subsequent calls) the strategy's ``transition()`` method (and
275+
optionally its ``force()`` method) can be decorated with the
276+
``@never_retry`` decorator.
277+
This decorator causes the strategy to store the encountered exception in its
278+
``broken`` attribute and raise a ``StrategyError`` for the original and all
279+
subsequent calls to the decorated methods.
280+
268281
Lets take a look at the builtin `BareboxStrategy`.
269282
The Status enum for the BareboxStrategy:
270283

0 commit comments

Comments
 (0)