Refactor SWF workflow execution to ease next timeout change
This commit is contained in:
parent
6027bf15c1
commit
7f2cbb79b0
@ -155,42 +155,19 @@ class WorkflowExecution(object):
|
|||||||
_timeout = self.first_timeout()
|
_timeout = self.first_timeout()
|
||||||
if _timeout:
|
if _timeout:
|
||||||
self.timeout(_timeout)
|
self.timeout(_timeout)
|
||||||
# TODO: process child policy on child workflows here or in timeout()
|
|
||||||
self._add_event(
|
|
||||||
"WorkflowExecutionTimedOut",
|
|
||||||
child_policy=self.child_policy,
|
|
||||||
event_timestamp=_timeout.timestamp,
|
|
||||||
timeout_type=self.timeout_type,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 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 _timeout:
|
if _timeout:
|
||||||
self.should_schedule_decision_next = True
|
self.timeout_decision_task(_timeout)
|
||||||
task.timeout(_timeout)
|
|
||||||
self._add_event(
|
|
||||||
"DecisionTaskTimedOut",
|
|
||||||
event_timestamp=_timeout.timestamp,
|
|
||||||
scheduled_event_id=task.scheduled_event_id,
|
|
||||||
started_event_id=task.started_event_id,
|
|
||||||
timeout_type=task.timeout_type,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 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 _timeout:
|
if _timeout:
|
||||||
self.should_schedule_decision_next = True
|
self.timeout_activity_task(_timeout)
|
||||||
task.timeout(_timeout)
|
|
||||||
self._add_event(
|
|
||||||
"ActivityTaskTimedOut",
|
|
||||||
details=task.details,
|
|
||||||
event_timestamp=_timeout.timestamp,
|
|
||||||
scheduled_event_id=task.scheduled_event_id,
|
|
||||||
started_event_id=task.started_event_id,
|
|
||||||
timeout_type=task.timeout_type,
|
|
||||||
)
|
|
||||||
# schedule decision task if needed
|
# schedule decision task if needed
|
||||||
# TODO: make decision appear as if it has been scheduled immediately after the timeout
|
# TODO: make decision appear as if it has been scheduled immediately after the timeout
|
||||||
if self.should_schedule_decision_next:
|
if self.should_schedule_decision_next:
|
||||||
@ -376,7 +353,7 @@ class WorkflowExecution(object):
|
|||||||
self.execution_status = "CLOSED"
|
self.execution_status = "CLOSED"
|
||||||
self.close_status = "COMPLETED"
|
self.close_status = "COMPLETED"
|
||||||
self.close_timestamp = now_timestamp()
|
self.close_timestamp = now_timestamp()
|
||||||
evt = self._add_event(
|
self._add_event(
|
||||||
"WorkflowExecutionCompleted",
|
"WorkflowExecutionCompleted",
|
||||||
decision_task_completed_event_id=event_id,
|
decision_task_completed_event_id=event_id,
|
||||||
result=result,
|
result=result,
|
||||||
@ -387,7 +364,7 @@ class WorkflowExecution(object):
|
|||||||
self.execution_status = "CLOSED"
|
self.execution_status = "CLOSED"
|
||||||
self.close_status = "FAILED"
|
self.close_status = "FAILED"
|
||||||
self.close_timestamp = now_timestamp()
|
self.close_timestamp = now_timestamp()
|
||||||
evt = self._add_event(
|
self._add_event(
|
||||||
"WorkflowExecutionFailed",
|
"WorkflowExecutionFailed",
|
||||||
decision_task_completed_event_id=event_id,
|
decision_task_completed_event_id=event_id,
|
||||||
details=details,
|
details=details,
|
||||||
@ -487,7 +464,7 @@ class WorkflowExecution(object):
|
|||||||
|
|
||||||
def complete_activity_task(self, task_token, result=None):
|
def complete_activity_task(self, task_token, result=None):
|
||||||
task = self._find_activity_task(task_token)
|
task = self._find_activity_task(task_token)
|
||||||
evt = self._add_event(
|
self._add_event(
|
||||||
"ActivityTaskCompleted",
|
"ActivityTaskCompleted",
|
||||||
scheduled_event_id=task.scheduled_event_id,
|
scheduled_event_id=task.scheduled_event_id,
|
||||||
started_event_id=task.started_event_id,
|
started_event_id=task.started_event_id,
|
||||||
@ -500,7 +477,7 @@ class WorkflowExecution(object):
|
|||||||
|
|
||||||
def fail_activity_task(self, task_token, reason=None, details=None):
|
def fail_activity_task(self, task_token, reason=None, details=None):
|
||||||
task = self._find_activity_task(task_token)
|
task = self._find_activity_task(task_token)
|
||||||
evt = self._add_event(
|
self._add_event(
|
||||||
"ActivityTaskFailed",
|
"ActivityTaskFailed",
|
||||||
scheduled_event_id=task.scheduled_event_id,
|
scheduled_event_id=task.scheduled_event_id,
|
||||||
started_event_id=task.started_event_id,
|
started_event_id=task.started_event_id,
|
||||||
@ -539,9 +516,41 @@ class WorkflowExecution(object):
|
|||||||
return _timeout
|
return _timeout
|
||||||
|
|
||||||
def timeout(self, timeout):
|
def timeout(self, timeout):
|
||||||
|
# TODO: process child policy on child workflows here or in the triggering function
|
||||||
self.execution_status = "CLOSED"
|
self.execution_status = "CLOSED"
|
||||||
self.close_status = "TIMED_OUT"
|
self.close_status = "TIMED_OUT"
|
||||||
self.timeout_type = timeout.kind
|
self.timeout_type = timeout.kind
|
||||||
|
self._add_event(
|
||||||
|
"WorkflowExecutionTimedOut",
|
||||||
|
child_policy=self.child_policy,
|
||||||
|
event_timestamp=timeout.timestamp,
|
||||||
|
timeout_type=self.timeout_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
def timeout_decision_task(self, _timeout):
|
||||||
|
self.should_schedule_decision_next = True
|
||||||
|
task = _timeout.obj
|
||||||
|
task.timeout(_timeout)
|
||||||
|
self._add_event(
|
||||||
|
"DecisionTaskTimedOut",
|
||||||
|
event_timestamp=_timeout.timestamp,
|
||||||
|
scheduled_event_id=task.scheduled_event_id,
|
||||||
|
started_event_id=task.started_event_id,
|
||||||
|
timeout_type=task.timeout_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
def timeout_activity_task(self, _timeout):
|
||||||
|
self.should_schedule_decision_next = True
|
||||||
|
task = _timeout.obj
|
||||||
|
task.timeout(_timeout)
|
||||||
|
self._add_event(
|
||||||
|
"ActivityTaskTimedOut",
|
||||||
|
details=task.details,
|
||||||
|
event_timestamp=_timeout.timestamp,
|
||||||
|
scheduled_event_id=task.scheduled_event_id,
|
||||||
|
started_event_id=task.started_event_id,
|
||||||
|
timeout_type=task.timeout_type,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def open(self):
|
def open(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user