Make timeout events appear at the right time in workflow history

This commit is contained in:
Jean-Baptiste Barth 2015-11-05 02:40:16 +01:00
parent d618585790
commit 65c35bfa69
2 changed files with 14 additions and 2 deletions

View File

@ -159,16 +159,19 @@ class WorkflowExecution(object):
self._add_event(
"WorkflowExecutionTimedOut",
child_policy=self.child_policy,
event_timestamp=_timeout.timestamp,
timeout_type=self.timeout_type,
)
# decision tasks timeouts
for task in self.decision_tasks:
if task.state == "STARTED" and task.first_timeout():
_timeout = task.first_timeout()
if task.state == "STARTED" and _timeout:
self.should_schedule_decision_next = True
task.process_timeouts()
self._add_event(
"DecisionTaskTimedOut",
event_timestamp=_timeout.timestamp,
scheduled_event_id=task.scheduled_event_id,
started_event_id=task.started_event_id,
timeout_type=task.timeout_type,
@ -176,17 +179,20 @@ class WorkflowExecution(object):
# activity tasks timeouts
for task in self.activity_tasks:
if task.open and task.first_timeout():
_timeout = task.first_timeout()
if task.open and _timeout:
self.should_schedule_decision_next = True
task.process_timeouts()
self._add_event(
"ActivityTaskTimedOut",
details=task.details,
event_timestamp=_timeout.timestamp,
scheduled_event_id=task.scheduled_event_id,
started_event_id=task.started_event_id,
timeout_type=task.timeout_type,
)
# schedule decision task if needed
# TODO: make decision appear as if it has been scheduled immediately after the timeout
if self.should_schedule_decision_next:
self.schedule_decision_task()

View File

@ -30,6 +30,8 @@ def test_activity_task_heartbeat_timeout():
resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut")
attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]
attrs["timeoutType"].should.equal("HEARTBEAT")
# checks that event has been emitted at 12:05:00, not 12:05:30
resp["events"][-2]["eventTimestamp"].should.equal(1420113900)
resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled")
@ -63,6 +65,8 @@ def test_decision_task_start_to_close_timeout():
attrs.should.equal({
"scheduledEventId": 2, "startedEventId": 3, "timeoutType": "START_TO_CLOSE"
})
# checks that event has been emitted at 12:05:00, not 12:05:30
resp["events"][-2]["eventTimestamp"].should.equal(1420113900)
# Workflow Execution Start to Close timeout
# Default value in workflow helpers: 2 hours
@ -92,3 +96,5 @@ def test_workflow_execution_start_to_close_timeout():
attrs.should.equal({
"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"
})
# checks that event has been emitted at 14:00:00, not 14:00:30
resp["events"][-1]["eventTimestamp"].should.equal(1420120800)