Implement start to close timeout on SWF decision tasks

This commit is contained in:
Jean-Baptiste Barth 2015-11-04 10:12:17 +01:00
commit 86973f2b87
6 changed files with 89 additions and 1 deletions

View file

@ -2,6 +2,8 @@ from __future__ import unicode_literals
from datetime import datetime
import uuid
from ..utils import now_timestamp
class DecisionTask(object):
def __init__(self, workflow_execution, scheduled_event_id):
@ -11,10 +13,13 @@ class DecisionTask(object):
self.scheduled_event_id = scheduled_event_id
self.previous_started_event_id = 0
self.started_event_id = None
self.started_timestamp = None
self.start_to_close_timeout = self.workflow_execution.task_start_to_close_timeout
self.state = "SCHEDULED"
# this is *not* necessarily coherent with workflow execution history,
# but that shouldn't be a problem for tests
self.scheduled_at = datetime.now()
self.timeout_type = None
def to_full_dict(self, reverse_order=False):
events = self.workflow_execution.events(reverse_order=reverse_order)
@ -33,7 +38,21 @@ class DecisionTask(object):
def start(self, started_event_id):
self.state = "STARTED"
self.started_timestamp = now_timestamp()
self.started_event_id = started_event_id
def complete(self):
self.state = "COMPLETED"
def has_timedout(self):
if self.state != "STARTED":
return False
# TODO: handle the "NONE" case
start_to_close_timeout = self.started_timestamp + \
int(self.start_to_close_timeout)
return start_to_close_timeout < now_timestamp()
def process_timeouts(self):
if self.has_timedout():
self.state = "TIMED_OUT"
self.timeout_type = "START_TO_CLOSE"