Skip to content

Commit 34b759e

Browse files
committed
Add retry on activity worker's fail
Totally untested! Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 5205d8a commit 34b759e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

simpleflow/swf/process/poller.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,18 @@ def poll_with_retry(self):
154154
)(self.poll)
155155
response = poll(task_list, identity=identity)
156156
return response
157+
158+
@abc.abstractmethod
159+
def fail(self, *args, **kwargs):
160+
"""fail; only relevant for activity workers."""
161+
raise NotImplementedError
162+
163+
def fail_with_retry(self, *args, **kwargs):
164+
fail = utils.retry.with_delay(
165+
nb_times=self.nb_retries,
166+
delay=utils.retry.exponential,
167+
log_with=logger.exception,
168+
on_exceptions=swf.exceptions.ResponseError,
169+
)(self.fail)
170+
response = fail(*args, **kwargs)
171+
return response

simpleflow/swf/process/worker/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def process(self, poller, token, task):
142142
except Exception as err:
143143
logger.exception("process error: {}".format(str(err)))
144144
tb = traceback.format_exc()
145-
return poller.fail(token, task, reason=str(err), details=tb)
145+
return poller.fail_with_retry(token, task, reason=str(err), details=tb)
146146

147147
try:
148148
poller.complete_with_retry(token, json_dumps(result))
@@ -152,7 +152,7 @@ def process(self, poller, token, task):
152152
task.activity_id,
153153
err,
154154
)
155-
poller.fail(token, task, reason)
155+
poller.fail_with_retry(token, task, reason)
156156

157157

158158
def process_task(poller, token, task):
@@ -204,7 +204,7 @@ def worker_alive():
204204
worker.pid
205205
))
206206
if worker.exitcode != 0:
207-
poller.fail(
207+
poller.fail_with_retry(
208208
token,
209209
task,
210210
reason='process {} died: exit code {}'.format(

0 commit comments

Comments
 (0)