Ensure activity and decision tasks cannot progress on a closed workflow

This is a second barrier because I'm a little nervous about this and I
don't want moto/swf to make any activity progress while in the real
world service, it's strictly impossible once the execution is closed.
Python doesn't seem to have any nice way of freezing an object so here
we go with a manual boundary...
This commit is contained in:
Jean-Baptiste Barth 2015-11-05 01:12:51 +01:00
commit 61bb550052
5 changed files with 60 additions and 4 deletions

View file

@ -2,6 +2,7 @@ from __future__ import unicode_literals
from datetime import datetime
import uuid
from ..exceptions import SWFWorkflowExecutionClosedError
from ..utils import now_timestamp
@ -21,6 +22,10 @@ class DecisionTask(object):
self.scheduled_at = datetime.now()
self.timeout_type = None
def _check_workflow_execution_open(self):
if not self.workflow_execution.open:
raise SWFWorkflowExecutionClosedError()
def to_full_dict(self, reverse_order=False):
events = self.workflow_execution.events(reverse_order=reverse_order)
hsh = {
@ -42,6 +47,7 @@ class DecisionTask(object):
self.started_event_id = started_event_id
def complete(self):
self._check_workflow_execution_open()
self.state = "COMPLETED"
def has_timedout(self):
@ -54,5 +60,9 @@ class DecisionTask(object):
def process_timeouts(self):
if self.has_timedout():
self.state = "TIMED_OUT"
self.timeout_type = "START_TO_CLOSE"
self.timeout()
def timeout(self):
self._check_workflow_execution_open()
self.state = "TIMED_OUT"
self.timeout_type = "START_TO_CLOSE"