Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Commit 43f7266

Browse files
author
Oleiade
committed
Merge branch 'release/0.1.31'
2 parents 87de1fc + d9d000e commit 43f7266

File tree

3 files changed

+107
-32
lines changed

3 files changed

+107
-32
lines changed

swf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
version = (0, 1, 29)
4+
version = (0, 1, 31)
55

66
__title__ = "python-simple-workflow"
77
__author__ = "Oleiade"

swf/actors/decider.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ def complete(self, task_token,
3535
made by the decider while processing this decision task
3636
:type decisions: list (of swf.models.decision.Decision)
3737
"""
38-
self.connection.respond_decision_task_completed(
39-
task_token,
40-
decisions,
41-
execution_context,
42-
)
38+
try:
39+
self.connection.respond_decision_task_completed(
40+
task_token,
41+
decisions,
42+
execution_context,
43+
)
44+
except SWFResponseError as e:
45+
if e.error_code == 'UnknownResourceFault':
46+
raise DoesNotExistError(
47+
"Unable to complete decision task with token: {}.\n"
48+
"Possible reasons: decision already completed or "
49+
"workflow execution is closed.\n"
50+
"Details: {}".format(task_token, e.body['message'])
51+
)
52+
53+
raise ResponseError(e.body['message'])
54+
4355

4456
def poll(self, task_list=None,
4557
identity=None,
@@ -76,13 +88,23 @@ def poll(self, task_list=None,
7688

7789
next_page = task.get('nextPageToken')
7890
while next_page:
79-
task = self.connection.poll_for_decision_task(
80-
self.domain.name,
81-
task_list=task_list,
82-
identity=identity,
83-
next_page_token=next_page,
84-
**kwargs
85-
)
91+
try:
92+
task = self.connection.poll_for_decision_task(
93+
self.domain.name,
94+
task_list=task_list,
95+
identity=identity,
96+
next_page_token=next_page,
97+
**kwargs
98+
)
99+
except SWFResponseError as e:
100+
if e.error_code == 'UnknownResourceFault':
101+
raise DoesNotExistError(
102+
"Unable to poll decision task.\n"
103+
"Reason: workflow execution is probably closed.\n"
104+
"Details: {}".format(task_token, e.body['message'])
105+
)
106+
107+
raise ResponseError(e.body['message'])
86108

87109
token = task.get('taskToken')
88110
if token is None:

swf/actors/worker.py

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ def cancel(self, task_token, details=None):
4242
:param details: provided details about cancel
4343
:type details: string
4444
"""
45-
return self.connection.respond_activity_task_canceled(task_token)
45+
try:
46+
return self.connection.respond_activity_task_canceled(task_token)
47+
except SWFResponseError as e:
48+
if e.error_code == 'UnknownResourceFault':
49+
raise DoesNotExistError(
50+
"Unable to cancel activity task with token: {}.\n"
51+
"Possible reasons: task already canceled or "
52+
"workflow execution is closed.\n"
53+
"Details: {}".format(task_token)
54+
)
55+
56+
raise ResponseError(e.body['message'])
4657

4758
def complete(self, task_token, result=None):
4859
"""Responds to ``swf` that the activity task is completed
@@ -53,10 +64,21 @@ def complete(self, task_token, result=None):
5364
:param result: The result of the activity task.
5465
:type result: string
5566
"""
56-
return self.connection.respond_activity_task_completed(
57-
task_token,
58-
result
59-
)
67+
try:
68+
return self.connection.respond_activity_task_completed(
69+
task_token,
70+
result
71+
)
72+
except SWFResponseError as e:
73+
if e.error_code == 'UnknownResourceFault':
74+
raise DoesNotExistError(
75+
"Unable to complete activity task with token: {}.\n"
76+
"Possible reasons: task already completed or "
77+
"workflow execution is closed.\n"
78+
"Details: {}".format(task_token, e.body['message'])
79+
)
80+
81+
raise ResponseError(e.body['message'])
6082

6183
def fail(self, task_token, details=None, reason=None):
6284
"""Replies to ``swf`` that the activity task failed
@@ -70,11 +92,22 @@ def fail(self, task_token, details=None, reason=None):
7092
:param reason: Description of the error that may assist in diagnostics
7193
:type reason: string
7294
"""
73-
return self.connection.respond_activity_task_failed(
74-
task_token,
75-
details,
76-
reason
77-
)
95+
try:
96+
return self.connection.respond_activity_task_failed(
97+
task_token,
98+
details,
99+
reason
100+
)
101+
except SWFResponseError as e:
102+
if e.error_code == 'UnknownResourceFault':
103+
raise DoesNotExistError(
104+
"Unable to fail activity task with token: {}.\n"
105+
"Possible reasons: task already failed or "
106+
"workflow execution is closed"
107+
"Details: {}".format(task_token, e.body['message'])
108+
)
109+
110+
raise ResponseError(e.body['message'])
78111

79112
def heartbeat(self, task_token, details=None):
80113
"""Records activity task heartbeat
@@ -85,10 +118,20 @@ def heartbeat(self, task_token, details=None):
85118
:param details: provided details about cancel
86119
:type details: string
87120
"""
88-
return self.connection.record_activity_task_heartbeat(
89-
task_token,
90-
details
91-
)
121+
try:
122+
return self.connection.record_activity_task_heartbeat(
123+
task_token,
124+
details
125+
)
126+
except SWFResponseError as e:
127+
if e.error_code == 'UnknownResourceFault':
128+
raise DoesNotExistError(
129+
"Unable to send activity task {} heartbeat.\n"
130+
"Possible reason: workflow execution is closed.\n"
131+
"Details: {}".format(task_token, e.body['message'])
132+
)
133+
134+
raise ResponseError(e.body['message'])
92135

93136
def poll(self, task_list=None, identity=None):
94137
"""Polls for an activity task to process from current
@@ -115,11 +158,21 @@ def poll(self, task_list=None, identity=None):
115158
task_list = task_list or self.task_list
116159
identity = identity or self.identity
117160

118-
polled_activity_data = self.connection.poll_for_activity_task(
119-
self.domain.name,
120-
task_list,
121-
identity=identity
122-
)
161+
try:
162+
polled_activity_data = self.connection.poll_for_activity_task(
163+
self.domain.name,
164+
task_list,
165+
identity=identity
166+
)
167+
except SWFResponseError as e:
168+
if e.error_code == 'UnknownResourceFault':
169+
raise DoesNotExistError(
170+
"Unable to poll activity task.\n"
171+
"Possible reason: workflow execution is probably closed.\n"
172+
"Details: {}".format(e.body['message'])
173+
)
174+
175+
raise ResponseError(e.body['message'])
123176

124177
if not 'taskToken' in polled_activity_data:
125178
raise PollTimeout("Activity Worker poll timed out")

0 commit comments

Comments
 (0)