Add SWF endpoint RespondActivityTaskFailed
This commit is contained in:
parent
c9e8ad03f8
commit
fd12e317f8
7 changed files with 100 additions and 8 deletions
|
|
@ -298,10 +298,7 @@ class SWFBackend(BaseBackend):
|
|||
count += len(pending)
|
||||
return count
|
||||
|
||||
def respond_activity_task_completed(self, task_token, result=None):
|
||||
self._check_string(task_token)
|
||||
self._check_none_or_string(result)
|
||||
# let's find the activity task
|
||||
def _find_activity_task_from_token(self, task_token):
|
||||
activity_task = None
|
||||
for domain in self.domains:
|
||||
for _, wfe in domain.workflow_executions.iteritems():
|
||||
|
|
@ -337,9 +334,23 @@ class SWFBackend(BaseBackend):
|
|||
"a bug in moto, please report it, thanks!"
|
||||
)
|
||||
# everything's good
|
||||
if activity_task:
|
||||
wfe = activity_task.workflow_execution
|
||||
wfe.complete_activity_task(activity_task.task_token, result=result)
|
||||
return activity_task
|
||||
|
||||
def respond_activity_task_completed(self, task_token, result=None):
|
||||
self._check_string(task_token)
|
||||
self._check_none_or_string(result)
|
||||
activity_task = self._find_activity_task_from_token(task_token)
|
||||
wfe = activity_task.workflow_execution
|
||||
wfe.complete_activity_task(activity_task.task_token, result=result)
|
||||
|
||||
def respond_activity_task_failed(self, task_token, reason=None, details=None):
|
||||
self._check_string(task_token)
|
||||
# TODO: implement length limits on reason and details (common pb with client libs)
|
||||
self._check_none_or_string(reason)
|
||||
self._check_none_or_string(details)
|
||||
activity_task = self._find_activity_task_from_token(task_token)
|
||||
wfe = activity_task.workflow_execution
|
||||
wfe.fail_activity_task(activity_task.task_token, reason=reason, details=details)
|
||||
|
||||
|
||||
swf_backends = {}
|
||||
|
|
|
|||
|
|
@ -36,3 +36,6 @@ class ActivityTask(object):
|
|||
|
||||
def complete(self):
|
||||
self.state = "COMPLETED"
|
||||
|
||||
def fail(self):
|
||||
self.state = "FAILED"
|
||||
|
|
|
|||
|
|
@ -121,6 +121,17 @@ class HistoryEvent(object):
|
|||
if hasattr(self, "result") and self.result is not None:
|
||||
hsh["result"] = self.result
|
||||
return hsh
|
||||
elif self.event_type == "ActivityTaskFailed":
|
||||
# TODO: maybe merge it with ActivityTaskCompleted (different optional params tho)
|
||||
hsh = {
|
||||
"scheduledEventId": self.scheduled_event_id,
|
||||
"startedEventId": self.started_event_id,
|
||||
}
|
||||
if hasattr(self, "reason") and self.reason is not None:
|
||||
hsh["reason"] = self.reason
|
||||
if hasattr(self, "details") and self.details is not None:
|
||||
hsh["details"] = self.details
|
||||
return hsh
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
"HistoryEvent does not implement attributes for type '{}'".format(self.event_type)
|
||||
|
|
|
|||
|
|
@ -443,3 +443,17 @@ class WorkflowExecution(object):
|
|||
self.open_counts["openActivityTasks"] -= 1
|
||||
# TODO: ensure we don't schedule multiple decisions at the same time!
|
||||
self.schedule_decision_task()
|
||||
|
||||
def fail_activity_task(self, task_token, reason=None, details=None):
|
||||
task = self._find_activity_task(task_token)
|
||||
evt = self._add_event(
|
||||
"ActivityTaskFailed",
|
||||
scheduled_event_id=task.scheduled_event_id,
|
||||
started_event_id=task.started_event_id,
|
||||
reason=reason,
|
||||
details=details,
|
||||
)
|
||||
task.fail()
|
||||
self.open_counts["openActivityTasks"] -= 1
|
||||
# TODO: ensure we don't schedule multiple decisions at the same time!
|
||||
self.schedule_decision_task()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue