Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RetryOnFail skill processor #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions skiros2_skill/src/skiros2_skill/core/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,39 @@ def processChildren(self, children, visitor):
return state
else:
return State.Success

class RetryOnFail():
"""
@brief Like Sequential, but retries up to max_retries if a child node fails.
Restarts all child nodes on failure.
"""

def __init__(self, max_retries=-1):
self.max_retries = max_retries
self.i = -1
self.index = 0

def printType(self):
return 'RetryOnFail({})'.format(self.max_retries)

def reset(self):
self.i = -1
self.index = 0

def processChildren(self, children, visitor):

for i in range(self.index, len(children)):
c = children[i]
state = c.visit(visitor)
if state == State.Failure:
self.index = 0
self.i += 1
if self.i == self.max_retries:
return State.Failure
else:
return State.Running
elif state != State.Success:
return state
self.index += 1

return State.Success