diff --git a/simpleflow/history.py b/simpleflow/history.py index c15224504..9ed842819 100644 --- a/simpleflow/history.py +++ b/simpleflow/history.py @@ -155,6 +155,8 @@ def get_activity(): "decision_task_completed_event_id": event.decision_task_completed_event_id, } if event.activity_id not in self._activities: + activity["retry"] = 0 + activity["attempt"] = 1 self._activities[event.activity_id] = activity self._tasks.append(activity) else: @@ -164,6 +166,8 @@ def get_activity(): # in ``retry``. As the state of the event mutates, it # corresponds to the last execution. self._activities[event.activity_id].update(activity) + self._activities[event.activity_id]["retry"] += 1 + self._activities[event.activity_id]["attempt"] += 1 elif event.state == "schedule_failed": activity = { "type": "activity", @@ -218,10 +222,6 @@ def get_activity(): "timed_out_timestamp": event.timestamp, } ) - if "retry" not in activity: - activity["retry"] = 0 - else: - activity["retry"] += 1 elif event.state == "failed": activity = get_activity() activity.update( @@ -233,10 +233,6 @@ def get_activity(): "failed_timestamp": event.timestamp, } ) - if "retry" not in activity: - activity["retry"] = 0 - else: - activity["retry"] += 1 elif event.state == "cancelled": activity = get_activity() activity.update( @@ -310,6 +306,8 @@ def get_workflow(): "decision_task_completed_event_id": event.decision_task_completed_event_id, } if event.workflow_id not in self._child_workflows: + workflow["retry"] = 0 + workflow["attempt"] = 1 self._child_workflows[event.workflow_id] = workflow self._tasks.append(workflow) else: @@ -322,6 +320,8 @@ def get_workflow(): f" we're @{event.id})" ) self._child_workflows[event.workflow_id].update(workflow) + self._child_workflows[event.workflow_id]["retry"] += 1 + self._child_workflows[event.workflow_id]["attempt"] += 1 elif event.state == "start_failed": workflow = { "type": "child_workflow", @@ -372,10 +372,6 @@ def get_workflow(): "failed_timestamp": event.timestamp, } ) - if "retry" not in workflow: - workflow["retry"] = 0 - else: - workflow["retry"] += 1 elif event.state == "timed_out": workflow = get_workflow() workflow.update( @@ -391,10 +387,6 @@ def get_workflow(): "timed_out_timestamp": event.timestamp, } ) - if "retry" not in workflow: - workflow["retry"] = 0 - else: - workflow["retry"] += 1 elif event.state == "canceled": workflow = get_workflow() workflow.update( diff --git a/simpleflow/swf/mapper/models/event/task.py b/simpleflow/swf/mapper/models/event/task.py index f0e9c8ff9..51c55a21c 100644 --- a/simpleflow/swf/mapper/models/event/task.py +++ b/simpleflow/swf/mapper/models/event/task.py @@ -66,6 +66,7 @@ class ActivityTaskEventDict(TypedDict): activity_id: int activity_type: ActivityType retry: int | None + attempt: int | None cause: str result: Any reason: str | None