Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Commit 3b692eb

Browse files
author
Oleiade
committed
Add finished property to History
1 parent f411e98 commit 3b692eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

swf/models/history.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from itertools import groupby
99

1010
from swf.models.event import EventFactory, CompiledEventFactory
11+
from swf.models.event.workflow import WorkflowExecutionEvent
1112
from swf.utils import cached_property
1213

1314

@@ -127,6 +128,25 @@ def first(self):
127128
"""
128129
return self.events[0]
129130

131+
@property
132+
def finished(self):
133+
"""Checks if the History matches with a finished Workflow
134+
Execution history state.
135+
"""
136+
completion_states = (
137+
'completed',
138+
'failed',
139+
'canceled',
140+
'terminated'
141+
)
142+
143+
if (isinstance(self.last, WorkflowExecutionEvent) and
144+
self.last.state in completion_states):
145+
return True
146+
147+
return False
148+
149+
130150
def filter(self, **kwargs):
131151
"""Filters the history based on kwargs events attributes
132152

0 commit comments

Comments
 (0)