From 6027bf15c1dbc15cf27959021ab8099296bb44a3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Thu, 5 Nov 2015 02:51:55 +0100 Subject: [PATCH] Move some timeout conditionals to concerned models --- moto/swf/models/activity_task.py | 2 +- moto/swf/models/decision_task.py | 6 +++++- moto/swf/models/workflow_execution.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/moto/swf/models/activity_task.py b/moto/swf/models/activity_task.py index 76d0eac70..eef8350e2 100644 --- a/moto/swf/models/activity_task.py +++ b/moto/swf/models/activity_task.py @@ -63,7 +63,7 @@ class ActivityTask(object): self.last_heartbeat_timestamp = now_timestamp() def first_timeout(self): - if not self.workflow_execution.open: + if not self.open or not self.workflow_execution.open: return None # TODO: handle the "NONE" case heartbeat_timeout_at = self.last_heartbeat_timestamp + \ diff --git a/moto/swf/models/decision_task.py b/moto/swf/models/decision_task.py index fb7b9d080..5474332a5 100644 --- a/moto/swf/models/decision_task.py +++ b/moto/swf/models/decision_task.py @@ -24,6 +24,10 @@ class DecisionTask(object): self.scheduled_at = datetime.now() self.timeout_type = None + @property + def started(self): + return self.state == "STARTED" + def _check_workflow_execution_open(self): if not self.workflow_execution.open: raise SWFWorkflowExecutionClosedError() @@ -53,7 +57,7 @@ class DecisionTask(object): self.state = "COMPLETED" def first_timeout(self): - if self.state != "STARTED" or not self.workflow_execution.open: + if not self.started or not self.workflow_execution.open: return None # TODO: handle the "NONE" case start_to_close_at = self.started_timestamp + int(self.start_to_close_timeout) diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index 0f619dca1..9a54f1729 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -166,7 +166,7 @@ class WorkflowExecution(object): # decision tasks timeouts for task in self.decision_tasks: _timeout = task.first_timeout() - if task.state == "STARTED" and _timeout: + if _timeout: self.should_schedule_decision_next = True task.timeout(_timeout) self._add_event( @@ -180,7 +180,7 @@ class WorkflowExecution(object): # activity tasks timeouts for task in self.activity_tasks: _timeout = task.first_timeout() - if task.open and _timeout: + if _timeout: self.should_schedule_decision_next = True task.timeout(_timeout) self._add_event(