Add missing attributes in DescribeWorkflowExecution responses

This commit is contained in:
Jean-Baptiste Barth 2015-10-31 21:13:44 +01:00
parent fd12e317f8
commit 98948a01c8
3 changed files with 32 additions and 2 deletions

View File

@ -53,6 +53,8 @@ class WorkflowExecution(object):
self.close_status = None
self.close_timestamp = None
self.execution_status = "OPEN"
self.latest_activity_task_timestamp = None
self.latest_execution_context = None
self.parent = None
self.start_timestamp = None
self.tag_list = [] # TODO
@ -72,6 +74,7 @@ class WorkflowExecution(object):
"openDecisionTasks": 0,
"openActivityTasks": 0,
"openChildWorkflowExecutions": 0,
"openLambdaFunctions": 0,
}
# events
self._events = []
@ -135,6 +138,11 @@ class WorkflowExecution(object):
hsh["executionConfiguration"][key] = getattr(self, attr)
#counters
hsh["openCounts"] = self.open_counts
#latest things
if self.latest_execution_context:
hsh["latestExecutionContext"] = self.latest_execution_context
if self.latest_activity_task_timestamp:
hsh["latestActivityTaskTimestamp"] = self.latest_activity_task_timestamp
return hsh
def events(self, reverse_order=False):
@ -226,6 +234,7 @@ class WorkflowExecution(object):
self.handle_decisions(evt.event_id, decisions)
if self.should_schedule_decision_next:
self.schedule_decision_task()
self.latest_execution_context = execution_context
def _check_decision_attributes(self, kind, value, decision_id):
problems = []
@ -413,6 +422,7 @@ class WorkflowExecution(object):
)
self.domain.add_to_activity_task_list(task_list, task)
self.open_counts["openActivityTasks"] += 1
self.latest_activity_task_timestamp = self._now_timestamp()
def _find_activity_task(self, task_token):
for task in self.activity_tasks:

View File

@ -195,10 +195,15 @@ def test_workflow_execution_fail():
wfe.events()[-1].details.should.equal("some details")
wfe.events()[-1].reason.should.equal("my rules")
@freeze_time("2015-01-01 12:00:00")
def test_workflow_execution_schedule_activity_task():
wfe = make_workflow_execution()
wfe.latest_activity_task_timestamp.should.be.none
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
wfe.latest_activity_task_timestamp.should.equal(1420110000.0)
wfe.open_counts["openActivityTasks"].should.equal(1)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ActivityTaskScheduled")
@ -305,7 +310,9 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision
wfe.start()
task_token = wfe.decision_tasks[-1].task_token
wfe.start_decision_task(task_token)
wfe.complete_decision_task(task_token, decisions=[
wfe.complete_decision_task(task_token,
execution_context="free-form execution context",
decisions=[
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
@ -322,6 +329,7 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision
},
])
wfe.latest_execution_context.should.equal("free-form execution context")
wfe.open_counts["openActivityTasks"].should.equal(0)
wfe.open_counts["openDecisionTasks"].should.equal(1)
last_events = wfe.events()[-3:]

View File

@ -1,4 +1,5 @@
import boto
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
@ -83,7 +84,10 @@ def test_respond_decision_task_completed_with_no_decision():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
resp = conn.respond_decision_task_completed(task_token)
resp = conn.respond_decision_task_completed(
task_token,
execution_context="free-form context",
)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
@ -96,10 +100,14 @@ def test_respond_decision_task_completed_with_no_decision():
])
evt = resp["events"][-1]
evt["decisionTaskCompletedEventAttributes"].should.equal({
"executionContext": "free-form context",
"scheduledEventId": 2,
"startedEventId": 3,
})
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp["latestExecutionContext"].should.equal("free-form context")
@mock_swf
def test_respond_decision_task_completed_with_wrong_token():
conn = setup_workflow()
@ -257,6 +265,7 @@ def test_respond_decision_task_completed_with_fail_workflow_execution():
attrs["details"].should.equal("foo")
@mock_swf
@freeze_time("2015-01-01 12:00:00")
def test_respond_decision_task_completed_with_schedule_activity_task():
conn = setup_workflow()
resp = conn.poll_for_decision_task("test-domain", "queue")
@ -302,3 +311,6 @@ def test_respond_decision_task_completed_with_schedule_activity_task():
"name": "my-task-list"
},
})
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp["latestActivityTaskTimestamp"].should.equal(1420110000.0)