Add WorkflowExecution.open to clarify code in some places

This commit is contained in:
Jean-Baptiste Barth 2015-11-04 22:25:27 +01:00
parent f38d23e483
commit 9c3996ff58
3 changed files with 8 additions and 4 deletions

View File

@ -243,7 +243,7 @@ class SWFBackend(BaseBackend):
raise SWFValidationException("Invalid token") raise SWFValidationException("Invalid token")
# decision task found, but WorflowExecution is CLOSED # decision task found, but WorflowExecution is CLOSED
wfe = decision_task.workflow_execution wfe = decision_task.workflow_execution
if wfe.execution_status != "OPEN": if not wfe.open:
raise SWFUnknownResourceFault( raise SWFUnknownResourceFault(
"execution", "execution",
"WorkflowExecution=[workflowId={0}, runId={1}]".format( "WorkflowExecution=[workflowId={0}, runId={1}]".format(
@ -331,7 +331,7 @@ class SWFBackend(BaseBackend):
raise SWFValidationException("Invalid token") raise SWFValidationException("Invalid token")
# activity task found, but WorflowExecution is CLOSED # activity task found, but WorflowExecution is CLOSED
wfe = activity_task.workflow_execution wfe = activity_task.workflow_execution
if wfe.execution_status != "OPEN": if not wfe.open:
raise SWFUnknownResourceFault( raise SWFUnknownResourceFault(
"execution", "execution",
"WorkflowExecution=[workflowId={0}, runId={1}]".format( "WorkflowExecution=[workflowId={0}, runId={1}]".format(

View File

@ -83,7 +83,7 @@ class Domain(object):
if w.workflow_id == workflow_id and w.run_id == run_id] if w.workflow_id == workflow_id and w.run_id == run_id]
else: else:
_all = [w for w in self.workflow_executions _all = [w for w in self.workflow_executions
if w.workflow_id == workflow_id and w.execution_status == "OPEN"] if w.workflow_id == workflow_id and w.open]
# reduce # reduce
wfe = _all[0] if _all else None wfe = _all[0] if _all else None
# raise if closed / none # raise if closed / none

View File

@ -523,7 +523,7 @@ class WorkflowExecution(object):
self.close_cause = "OPERATOR_INITIATED" self.close_cause = "OPERATOR_INITIATED"
def has_timedout(self): def has_timedout(self):
if self.execution_status != "OPEN" or not self.start_timestamp: if not self.open or not self.start_timestamp:
return False return False
# TODO: handle the "NONE" case # TODO: handle the "NONE" case
start_to_close_timeout = self.start_timestamp + \ start_to_close_timeout = self.start_timestamp + \
@ -535,3 +535,7 @@ class WorkflowExecution(object):
self.execution_status = "CLOSED" self.execution_status = "CLOSED"
self.close_status = "TIMED_OUT" self.close_status = "TIMED_OUT"
self.timeout_type = "START_TO_CLOSE" self.timeout_type = "START_TO_CLOSE"
@property
def open(self):
return self.execution_status == "OPEN"