Move some timeout conditionals to concerned models

This commit is contained in:
Jean-Baptiste Barth 2015-11-05 02:51:55 +01:00
parent d007dfe3ff
commit 6027bf15c1
3 changed files with 8 additions and 4 deletions

View File

@ -63,7 +63,7 @@ class ActivityTask(object):
self.last_heartbeat_timestamp = now_timestamp() self.last_heartbeat_timestamp = now_timestamp()
def first_timeout(self): def first_timeout(self):
if not self.workflow_execution.open: if not self.open or not self.workflow_execution.open:
return None return None
# TODO: handle the "NONE" case # TODO: handle the "NONE" case
heartbeat_timeout_at = self.last_heartbeat_timestamp + \ heartbeat_timeout_at = self.last_heartbeat_timestamp + \

View File

@ -24,6 +24,10 @@ class DecisionTask(object):
self.scheduled_at = datetime.now() self.scheduled_at = datetime.now()
self.timeout_type = None self.timeout_type = None
@property
def started(self):
return self.state == "STARTED"
def _check_workflow_execution_open(self): def _check_workflow_execution_open(self):
if not self.workflow_execution.open: if not self.workflow_execution.open:
raise SWFWorkflowExecutionClosedError() raise SWFWorkflowExecutionClosedError()
@ -53,7 +57,7 @@ class DecisionTask(object):
self.state = "COMPLETED" self.state = "COMPLETED"
def first_timeout(self): 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 return None
# TODO: handle the "NONE" case # TODO: handle the "NONE" case
start_to_close_at = self.started_timestamp + int(self.start_to_close_timeout) start_to_close_at = self.started_timestamp + int(self.start_to_close_timeout)

View File

@ -166,7 +166,7 @@ class WorkflowExecution(object):
# decision tasks timeouts # decision tasks timeouts
for task in self.decision_tasks: for task in self.decision_tasks:
_timeout = task.first_timeout() _timeout = task.first_timeout()
if task.state == "STARTED" and _timeout: if _timeout:
self.should_schedule_decision_next = True self.should_schedule_decision_next = True
task.timeout(_timeout) task.timeout(_timeout)
self._add_event( self._add_event(
@ -180,7 +180,7 @@ class WorkflowExecution(object):
# activity tasks timeouts # activity tasks timeouts
for task in self.activity_tasks: for task in self.activity_tasks:
_timeout = task.first_timeout() _timeout = task.first_timeout()
if task.open and _timeout: if _timeout:
self.should_schedule_decision_next = True self.should_schedule_decision_next = True
task.timeout(_timeout) task.timeout(_timeout)
self._add_event( self._add_event(