From 2a190f645c212d7fdde69601d2e81dbc52e2a6b4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Sun, 3 Sep 2023 23:37:36 +0200 Subject: [PATCH 1/2] Fix 'retry' count in simpleflow History --- simpleflow/history.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/simpleflow/history.py b/simpleflow/history.py index c15224504..8886239f3 100644 --- a/simpleflow/history.py +++ b/simpleflow/history.py @@ -155,6 +155,7 @@ 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 self._activities[event.activity_id] = activity self._tasks.append(activity) else: @@ -164,6 +165,7 @@ 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 elif event.state == "schedule_failed": activity = { "type": "activity", @@ -218,10 +220,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 +231,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 +304,7 @@ 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 self._child_workflows[event.workflow_id] = workflow self._tasks.append(workflow) else: @@ -322,6 +317,7 @@ def get_workflow(): f" we're @{event.id})" ) self._child_workflows[event.workflow_id].update(workflow) + self._child_workflows[event.workflow_id]["retry"] += 1 elif event.state == "start_failed": workflow = { "type": "child_workflow", @@ -372,10 +368,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 +383,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( From df41eddf0d6688d8c40e5d9379a89cb652608811 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Sun, 3 Sep 2023 23:37:51 +0200 Subject: [PATCH 2/2] Add 'attempt' count in simpleflow History --- simpleflow/history.py | 4 ++++ simpleflow/swf/mapper/models/event/task.py | 1 + 2 files changed, 5 insertions(+) diff --git a/simpleflow/history.py b/simpleflow/history.py index 8886239f3..9ed842819 100644 --- a/simpleflow/history.py +++ b/simpleflow/history.py @@ -156,6 +156,7 @@ def get_activity(): } 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: @@ -166,6 +167,7 @@ def get_activity(): # 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", @@ -305,6 +307,7 @@ def get_workflow(): } 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: @@ -318,6 +321,7 @@ def get_workflow(): ) 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", 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