diff --git a/moto/swf/models/__init__.py b/moto/swf/models/__init__.py index 622f38a02..5b4b96c87 100644 --- a/moto/swf/models/__init__.py +++ b/moto/swf/models/__init__.py @@ -191,6 +191,16 @@ class SWFBackend(BaseBackend): else: return None + def count_pending_decision_tasks(self, domain_name, task_list): + self._check_string(domain_name) + self._check_string(task_list) + domain = self._get_domain(domain_name) + count = 0 + for _, wfe in domain.workflow_executions.iteritems(): + if wfe.task_list == task_list: + count += wfe.open_counts["openDecisionTasks"] + return count + swf_backends = {} for region in boto.swf.regions(): diff --git a/moto/swf/responses.py b/moto/swf/responses.py index 8f8e86747..7832e3ebf 100644 --- a/moto/swf/responses.py +++ b/moto/swf/responses.py @@ -236,3 +236,9 @@ class SWFResponse(BaseResponse): ) else: return json.dumps({"previousStartedEventId": 0, "startedEventId": 0}) + + def count_pending_decision_tasks(self): + domain_name = self._params["domain"] + task_list = self._params["taskList"]["name"] + count = self.swf_backend.count_pending_decision_tasks(domain_name, task_list) + return json.dumps({"count": count, "truncated": False}) diff --git a/tests/test_swf/test_decision_tasks.py b/tests/test_swf/test_decision_tasks.py index 313736d7d..06cdd4556 100644 --- a/tests/test_swf/test_decision_tasks.py +++ b/tests/test_swf/test_decision_tasks.py @@ -57,3 +57,18 @@ def test_poll_for_decision_task_with_reverse_order(): resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True) types = [evt["eventType"] for evt in resp["events"]] types.should.equal(["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]) + + +# CountPendingDecisionTasks endpoint +@mock_swf +def test_count_pending_decision_tasks(): + conn = setup_workflow() + conn.poll_for_decision_task("test-domain", "queue") + resp = conn.count_pending_decision_tasks("test-domain", "queue") + resp.should.equal({"count": 1, "truncated": False}) + +@mock_swf +def test_count_pending_decision_tasks_on_non_existent_task_list(): + conn = setup_workflow() + resp = conn.count_pending_decision_tasks("test-domain", "non-existent") + resp.should.equal({"count": 0, "truncated": False})