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

Commit f99b68e

Browse files
committed
Merge pull request #56 from botify-labs/bugfix/allow-close-time-filters-on-wfe-querysets
Allow close time filters in WorkflowExecutionQueryset.filter()
2 parents f73397a + ad049bc commit f99b68e

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

swf/querysets/workflow.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,27 @@ def filter(self,
568568
if status == WorkflowExecution.STATUS_OPEN:
569569
oldest_date = kwargs.pop('oldest_date', 30)
570570
else:
571-
oldest_date = kwargs.pop('start_oldest_date', 30)
571+
# The SWF docs on ListClosedWorkflowExecutions state that:
572+
#
573+
# "startTimeFilter and closeTimeFilter are mutually exclusive"
574+
#
575+
# so we must figure out if we have to add a default value for
576+
# start_oldest_date or not.
577+
if "close_latest_date" in kwargs or "close_oldest_date" in kwargs:
578+
default_oldest_date = None
579+
else:
580+
default_oldest_date = 30
581+
oldest_date = kwargs.pop('start_oldest_date', default_oldest_date)
582+
583+
# Compute a timestamp from the delta in days we got from params
584+
# If oldest_date is blank at this point, it's because we didn't want
585+
# it, so let's leave it blank and assume the user provided an other
586+
# time filter.
587+
if oldest_date:
588+
start_oldest_date = int(datetime_timestamp(past_day(oldest_date)))
589+
else:
590+
start_oldest_date = None
572591

573-
start_oldest_date = datetime_timestamp(past_day(oldest_date))
574592
return [self.to_WorkflowExecution(self.domain, wfe) for wfe in
575593
self._list_items(
576594
*args,
@@ -579,7 +597,7 @@ def filter(self,
579597
workflow_id=workflow_id,
580598
workflow_name=workflow_type_name,
581599
workflow_version=workflow_type_version,
582-
start_oldest_date=int(start_oldest_date),
600+
start_oldest_date=start_oldest_date,
583601
tag=tag,
584602
**kwargs
585603
)]

tests/querysets/test_workflow.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import unittest
44

5-
from mock import patch
5+
from mock import patch, Mock
66
from boto.swf.layer1 import Layer1
77
from boto.exception import SWFResponseError
88

@@ -316,4 +316,20 @@ def test_get_invalid_workflow_execution(self):
316316
"message": "Whatever",
317317
}
318318
)
319-
self.weq.get("mocked-workflow-id", "mocked-run-id")
319+
self.weq.get("mocked-workflow-id", "mocked-run-id")
320+
321+
def test_filter_without_close_time_filter(self):
322+
self.weq._list_items = Mock(return_value=[])
323+
qs = self.weq.filter()
324+
self.weq._list_items.assert_called_once()
325+
kwargs = self.weq._list_items.call_args[1]
326+
self.assertIsInstance(kwargs["start_oldest_date"], int)
327+
328+
def test_filter_with_close_time_filter(self):
329+
self.weq._list_items = Mock(return_value=[])
330+
qs = self.weq.filter(status=WorkflowExecution.STATUS_CLOSED,
331+
close_latest_date=5)
332+
self.weq._list_items.assert_called_once()
333+
kwargs = self.weq._list_items.call_args[1]
334+
self.assertIsNone(kwargs["start_oldest_date"])
335+
self.assertIsInstance(kwargs["close_latest_date"], int)

0 commit comments

Comments
 (0)