Add SWF endpoint CountPendingActivityTasks
This commit is contained in:
parent
761ab816f9
commit
08643945df
@ -287,6 +287,17 @@ class SWFBackend(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def count_pending_activity_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 _task_list, tasks in domain.activity_task_lists.iteritems():
|
||||||
|
if _task_list == task_list:
|
||||||
|
pending = [t for t in tasks if t.state in ["SCHEDULED", "STARTED"]]
|
||||||
|
count += len(pending)
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
swf_backends = {}
|
swf_backends = {}
|
||||||
for region in boto.swf.regions():
|
for region in boto.swf.regions():
|
||||||
|
@ -242,7 +242,6 @@ class SWFResponse(BaseResponse):
|
|||||||
count = self.swf_backend.count_pending_decision_tasks(domain_name, task_list)
|
count = self.swf_backend.count_pending_decision_tasks(domain_name, task_list)
|
||||||
return json.dumps({"count": count, "truncated": False})
|
return json.dumps({"count": count, "truncated": False})
|
||||||
|
|
||||||
|
|
||||||
def respond_decision_task_completed(self):
|
def respond_decision_task_completed(self):
|
||||||
task_token = self._params["taskToken"]
|
task_token = self._params["taskToken"]
|
||||||
execution_context = self._params.get("executionContext")
|
execution_context = self._params.get("executionContext")
|
||||||
@ -265,3 +264,9 @@ class SWFResponse(BaseResponse):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return json.dumps({"startedEventId": 0})
|
return json.dumps({"startedEventId": 0})
|
||||||
|
|
||||||
|
def count_pending_activity_tasks(self):
|
||||||
|
domain_name = self._params["domain"]
|
||||||
|
task_list = self._params["taskList"]["name"]
|
||||||
|
count = self.swf_backend.count_pending_activity_tasks(domain_name, task_list)
|
||||||
|
return json.dumps({"count": count, "truncated": False})
|
||||||
|
@ -44,3 +44,28 @@ def test_poll_for_activity_task_on_non_existent_queue():
|
|||||||
resp = conn.poll_for_activity_task("test-domain", "non-existent-queue")
|
resp = conn.poll_for_activity_task("test-domain", "non-existent-queue")
|
||||||
resp.should.equal({"startedEventId": 0})
|
resp.should.equal({"startedEventId": 0})
|
||||||
|
|
||||||
|
|
||||||
|
# CountPendingActivityTasks endpoint
|
||||||
|
@mock_swf
|
||||||
|
def test_count_pending_activity_tasks():
|
||||||
|
conn = setup_workflow()
|
||||||
|
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
|
||||||
|
conn.respond_decision_task_completed(decision_token, decisions=[
|
||||||
|
{
|
||||||
|
"decisionType": "ScheduleActivityTask",
|
||||||
|
"scheduleActivityTaskDecisionAttributes": {
|
||||||
|
"activityId": "my-activity-001",
|
||||||
|
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||||
|
"taskList": { "name": "activity-task-list" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
resp = conn.count_pending_activity_tasks("test-domain", "activity-task-list")
|
||||||
|
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_activity_tasks("test-domain", "non-existent")
|
||||||
|
resp.should.equal({"count": 0, "truncated": False})
|
||||||
|
Loading…
Reference in New Issue
Block a user