Add SWF endpoint RecordActivityTaskHeartbeat
This commit is contained in:
parent
804d2e91b5
commit
f576f3765c
9 changed files with 94 additions and 12 deletions
|
|
@ -364,6 +364,12 @@ class SWFBackend(BaseBackend):
|
|||
wfe = domain.get_workflow_execution(workflow_id, run_id=run_id, raise_if_closed=True)
|
||||
wfe.terminate(child_policy=child_policy, details=details, reason=reason)
|
||||
|
||||
def record_activity_task_heartbeat(self, task_token, details=None):
|
||||
self._check_string(task_token)
|
||||
self._check_none_or_string(details)
|
||||
activity_task = self._find_activity_task_from_token(task_token)
|
||||
activity_task.reset_heartbeat_clock()
|
||||
|
||||
|
||||
swf_backends = {}
|
||||
for region in boto.swf.regions():
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
|||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from ..utils import now_timestamp
|
||||
|
||||
|
||||
class ActivityTask(object):
|
||||
def __init__(self, activity_id, activity_type, scheduled_event_id,
|
||||
|
|
@ -9,6 +11,7 @@ class ActivityTask(object):
|
|||
self.activity_id = activity_id
|
||||
self.activity_type = activity_type
|
||||
self.input = input
|
||||
self.last_heartbeat_timestamp = now_timestamp()
|
||||
self.scheduled_event_id = scheduled_event_id
|
||||
self.started_event_id = None
|
||||
self.state = "SCHEDULED"
|
||||
|
|
@ -39,3 +42,6 @@ class ActivityTask(object):
|
|||
|
||||
def fail(self):
|
||||
self.state = "FAILED"
|
||||
|
||||
def reset_heartbeat_clock(self):
|
||||
self.last_heartbeat_timestamp = now_timestamp()
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ from __future__ import unicode_literals
|
|||
from datetime import datetime
|
||||
from time import mktime
|
||||
|
||||
from ..utils import decapitalize
|
||||
from ..utils import decapitalize, now_timestamp
|
||||
|
||||
|
||||
class HistoryEvent(object):
|
||||
def __init__(self, event_id, event_type, **kwargs):
|
||||
self.event_id = event_id
|
||||
self.event_type = event_type
|
||||
self.event_timestamp = float(mktime(datetime.now().timetuple()))
|
||||
self.event_timestamp = now_timestamp()
|
||||
for key, value in kwargs.iteritems():
|
||||
self.__setattr__(key, value)
|
||||
# break soon if attributes are not valid
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from ..exceptions import (
|
|||
SWFValidationException,
|
||||
SWFDecisionValidationException,
|
||||
)
|
||||
from ..utils import decapitalize
|
||||
from ..utils import decapitalize, now_timestamp
|
||||
from .activity_task import ActivityTask
|
||||
from .activity_type import ActivityType
|
||||
from .decision_task import DecisionTask
|
||||
|
|
@ -161,12 +161,8 @@ class WorkflowExecution(object):
|
|||
self._events.append(evt)
|
||||
return evt
|
||||
|
||||
# TODO: move it in utils
|
||||
def _now_timestamp(self):
|
||||
return float(mktime(datetime.now().timetuple()))
|
||||
|
||||
def start(self):
|
||||
self.start_timestamp = self._now_timestamp()
|
||||
self.start_timestamp = now_timestamp()
|
||||
self._add_event(
|
||||
"WorkflowExecutionStarted",
|
||||
workflow_execution=self,
|
||||
|
|
@ -333,7 +329,7 @@ class WorkflowExecution(object):
|
|||
def complete(self, event_id, result=None):
|
||||
self.execution_status = "CLOSED"
|
||||
self.close_status = "COMPLETED"
|
||||
self.close_timestamp = self._now_timestamp()
|
||||
self.close_timestamp = now_timestamp()
|
||||
evt = self._add_event(
|
||||
"WorkflowExecutionCompleted",
|
||||
decision_task_completed_event_id=event_id,
|
||||
|
|
@ -344,7 +340,7 @@ class WorkflowExecution(object):
|
|||
# TODO: implement lenght constraints on details/reason
|
||||
self.execution_status = "CLOSED"
|
||||
self.close_status = "FAILED"
|
||||
self.close_timestamp = self._now_timestamp()
|
||||
self.close_timestamp = now_timestamp()
|
||||
evt = self._add_event(
|
||||
"WorkflowExecutionFailed",
|
||||
decision_task_completed_event_id=event_id,
|
||||
|
|
@ -423,7 +419,7 @@ class WorkflowExecution(object):
|
|||
)
|
||||
self.domain.add_to_activity_task_list(task_list, task)
|
||||
self.open_counts["openActivityTasks"] += 1
|
||||
self.latest_activity_task_timestamp = self._now_timestamp()
|
||||
self.latest_activity_task_timestamp = now_timestamp()
|
||||
|
||||
def _find_activity_task(self, task_token):
|
||||
for task in self.activity_tasks:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue