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

Commit b7aa3a5

Browse files
author
Oleiade
committed
Add HistoryQuerySet
1 parent 1ea01d3 commit b7aa3a5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

swf/querysets/history.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from swf.models import History
2+
from swf.querysets.base import BaseQuerySet
3+
4+
5+
class HistoryQuerySet(BaseQuerySet):
6+
"""WorkflowExecution history queryset"""
7+
def __init__(self, domain, *args, **kwargs):
8+
super(HistoryQuerySet, self).__init__(*args, **kwargs)
9+
self.domain = domain
10+
11+
def get(self, run_id, workflow_id, page_size=None, max_results=None, reverse=None):
12+
"""Retrieves a WorkflowExecution history
13+
14+
:param run_id: unique identifier of the workflow execution
15+
:type run_id: string
16+
17+
:param workflow_id: The user defined identifier associated with the workflow execution
18+
:type workflow_id: string
19+
20+
:param max_results: Max output history size. Retrieved history will be shrinked
21+
if it's size is greater than max_results.
22+
:type max_results: int
23+
24+
:param page_size: Swf api response page size: controls how many history events
25+
will be returned at each requests. Keep in mind that until
26+
max_results history size is reached, next pages will be
27+
requested.
28+
:type page_size: int
29+
30+
:param reverse: Should the history events be retrieved in reverse order.
31+
:type reverse: bool
32+
"""
33+
reverse = reverse or False
34+
page_size = page_size or 100
35+
events = []
36+
37+
if max_results < page_size:
38+
page_size = max_results
39+
40+
response = self.connection.get_workflow_execution_history(
41+
self.domain.name,
42+
run_id,
43+
workflow_id,
44+
maximum_page_size=page_size,
45+
reverse_order=reverse)
46+
events = response['events']
47+
48+
next_page = response.get('nextPageToken')
49+
while next_page is not None and len(events) < max_results:
50+
response = self.connection.get_workflow_execution_history(
51+
self.domain.name,
52+
run_id,
53+
workflow_id,
54+
maximum_page_size=page_size,
55+
next_page_token=next_page,
56+
reverse_order=reverse
57+
)
58+
events.extend(response['events'])
59+
next_page = response.get('nextPageToken')
60+
61+
return History.from_event_list(events)

0 commit comments

Comments
 (0)