Add SWF endpoint CountPendingDecisionTasks

This commit is contained in:
Jean-Baptiste Barth 2015-10-11 22:14:16 +02:00
parent 4e223d2318
commit a137e5c5c9
3 changed files with 31 additions and 0 deletions

View File

@ -191,6 +191,16 @@ class SWFBackend(BaseBackend):
else: else:
return None 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 = {} swf_backends = {}
for region in boto.swf.regions(): for region in boto.swf.regions():

View File

@ -236,3 +236,9 @@ class SWFResponse(BaseResponse):
) )
else: else:
return json.dumps({"previousStartedEventId": 0, "startedEventId": 0}) 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})

View File

@ -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) resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True)
types = [evt["eventType"] for evt in resp["events"]] types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]) 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})