Add SWF endpoint PollForDecisionTask and associated DecisionTask model

This commit is contained in:
Jean-Baptiste Barth 2015-10-11 14:02:55 +02:00
commit c16da9da2d
7 changed files with 213 additions and 3 deletions

View file

@ -0,0 +1,35 @@
from __future__ import unicode_literals
from datetime import datetime
import uuid
class DecisionTask(object):
def __init__(self, workflow_execution, scheduled_event_id):
self.workflow_execution = workflow_execution
self.workflow_type = workflow_execution.workflow_type
self.task_token = str(uuid.uuid4())
self.scheduled_event_id = scheduled_event_id
self.previous_started_event_id = 0
self.started_event_id = None
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()
def to_full_dict(self):
hsh = {
"events": [
evt.to_dict() for evt in self.workflow_execution.events
],
"taskToken": self.task_token,
"previousStartedEventId": self.previous_started_event_id,
"workflowExecution": self.workflow_execution.to_short_dict(),
"workflowType": self.workflow_type.to_short_dict(),
}
if self.started_event_id:
hsh["startedEventId"] = self.started_event_id
return hsh
def start(self, started_event_id):
self.state = "STARTED"
self.started_event_id = started_event_id