{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/comments/55860158","id":55860158,"diff_hunk":"@@ -0,0 +1,41 @@\n+import time\n+from datetime import datetime\n+from exceptions import TimeoutException\n+\n+DEFAULT_RETRY_TIMEOUT = 60\n+\n+\n+def qps_retry(f):\n+    def wrapped_f(*args, **kw):\n+        return QPSService().call(f, *args, **kw)\n+    return wrapped_f\n+\n+\n+class QPSService:\n+\n+    def __init__(self, queries_per_second=10,\n+                 retry_timeout=DEFAULT_RETRY_TIMEOUT):\n+        self._queries_per_second = queries_per_second\n+        self._retry_timeout = retry_timeout\n+\n+    def call(self, fn, *args, **kwargs):\n+        start_time = datetime.now()\n+        attempt_number = 1\n+        while True:\n+            try:\n+                return fn(*args, **kwargs)\n+            except Exception as e:\n+                if hasattr(e, 'response') and e.response.status_code == 429:\n+                    self.retry(start_time, attempt_number)\n+                else:\n+                    raise e\n+            attempt_number += 1\n+\n+    def retry(self, first_request_time, retry_count):\n+        elapsed = datetime.now() - first_request_time\n+        if elapsed.seconds > self._retry_timeout:\n+            raise TimeoutException()\n+\n+        delay = (float(self._queries_per_second)/100) * 1.5 ** retry_count","path":"server/lib/python/cartodb_services/cartodb_services/mapzen/qps.py","position":39,"original_position":39,"commit_id":"4f3f9bd24765940ecf0cbb70e4c13429d4d68481","original_commit_id":"4f3f9bd24765940ecf0cbb70e4c13429d4d68481","user":{"login":"rafatower","id":1914276,"avatar_url":"https://avatars.githubusercontent.com/u/1914276?v=3","gravatar_id":"","url":"https://api.github.com/users/rafatower","html_url":"https://github.com/rafatower","followers_url":"https://api.github.com/users/rafatower/followers","following_url":"https://api.github.com/users/rafatower/following{/other_user}","gists_url":"https://api.github.com/users/rafatower/gists{/gist_id}","starred_url":"https://api.github.com/users/rafatower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafatower/subscriptions","organizations_url":"https://api.github.com/users/rafatower/orgs","repos_url":"https://api.github.com/users/rafatower/repos","events_url":"https://api.github.com/users/rafatower/events{/privacy}","received_events_url":"https://api.github.com/users/rafatower/received_events","type":"User","site_admin":false},"body":"a small comment in the code explaining this bit of code would be appreciated.\r\n\r\nIt is customary to use `100.0`: instruct the bytecode to create a float literal instead of an integer that needs most likely to be cast.","created_at":"2016-03-11T17:26:23Z","updated_at":"2016-03-11T17:26:23Z","html_url":"https://github.com/CartoDB/dataservices-api/pull/110#discussion_r55860158","pull_request_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/comments/55860158"},"html":{"href":"https://github.com/CartoDB/dataservices-api/pull/110#discussion_r55860158"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110","id":62554909,"html_url":"https://github.com/CartoDB/dataservices-api/pull/110","diff_url":"https://github.com/CartoDB/dataservices-api/pull/110.diff","patch_url":"https://github.com/CartoDB/dataservices-api/pull/110.patch","issue_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/110","number":110,"state":"open","locked":false,"title":"QPS manager for Mapzen","user":{"login":"ethervoid","id":741240,"avatar_url":"https://avatars.githubusercontent.com/u/741240?v=3","gravatar_id":"","url":"https://api.github.com/users/ethervoid","html_url":"https://github.com/ethervoid","followers_url":"https://api.github.com/users/ethervoid/followers","following_url":"https://api.github.com/users/ethervoid/following{/other_user}","gists_url":"https://api.github.com/users/ethervoid/gists{/gist_id}","starred_url":"https://api.github.com/users/ethervoid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethervoid/subscriptions","organizations_url":"https://api.github.com/users/ethervoid/orgs","repos_url":"https://api.github.com/users/ethervoid/repos","events_url":"https://api.github.com/users/ethervoid/events{/privacy}","received_events_url":"https://api.github.com/users/ethervoid/received_events","type":"User","site_admin":false},"body":"QPS manager for the Mapzen functions.","created_at":"2016-03-11T15:04:35Z","updated_at":"2016-03-11T17:26:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"019a8d4373de7f77d90c01c5e8a1eda0c93a1e33","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110/commits","review_comments_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110/comments","review_comment_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/110/comments","statuses_url":"https://api.github.com/repos/CartoDB/dataservices-api/statuses/4f3f9bd24765940ecf0cbb70e4c13429d4d68481","head":{"label":"CartoDB:qps_for_mapzen_services","ref":"qps_for_mapzen_services","sha":"4f3f9bd24765940ecf0cbb70e4c13429d4d68481","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":45457790,"name":"dataservices-api","full_name":"CartoDB/dataservices-api","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/dataservices-api","description":"The CartoDB Geocoder SQL API (server and client FTM)","fork":false,"url":"https://api.github.com/repos/CartoDB/dataservices-api","forks_url":"https://api.github.com/repos/CartoDB/dataservices-api/forks","keys_url":"https://api.github.com/repos/CartoDB/dataservices-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/dataservices-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/dataservices-api/teams","hooks_url":"https://api.github.com/repos/CartoDB/dataservices-api/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/dataservices-api/events","assignees_url":"https://api.github.com/repos/CartoDB/dataservices-api/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/dataservices-api/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/dataservices-api/tags","blobs_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/dataservices-api/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/dataservices-api/languages","stargazers_url":"https://api.github.com/repos/CartoDB/dataservices-api/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/dataservices-api/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/dataservices-api/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/dataservices-api/subscription","commits_url":"https://api.github.com/repos/CartoDB/dataservices-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/dataservices-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/dataservices-api/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/dataservices-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/dataservices-api/merges","archive_url":"https://api.github.com/repos/CartoDB/dataservices-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/dataservices-api/downloads","issues_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/dataservices-api/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/dataservices-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/dataservices-api/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/dataservices-api/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/dataservices-api/deployments","created_at":"2015-11-03T10:05:38Z","updated_at":"2016-02-16T13:37:47Z","pushed_at":"2016-03-11T17:21:01Z","git_url":"git://github.com/CartoDB/dataservices-api.git","ssh_url":"git@github.com:CartoDB/dataservices-api.git","clone_url":"https://github.com/CartoDB/dataservices-api.git","svn_url":"https://github.com/CartoDB/dataservices-api","homepage":null,"size":469,"stargazers_count":2,"watchers_count":2,"language":"PLpgSQL","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":16,"forks":1,"open_issues":16,"watchers":2,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"3bf81b426bb778ba55d5a9b7cf20f2b9edb16f09","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":45457790,"name":"dataservices-api","full_name":"CartoDB/dataservices-api","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/dataservices-api","description":"The CartoDB Geocoder SQL API (server and client FTM)","fork":false,"url":"https://api.github.com/repos/CartoDB/dataservices-api","forks_url":"https://api.github.com/repos/CartoDB/dataservices-api/forks","keys_url":"https://api.github.com/repos/CartoDB/dataservices-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/dataservices-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/dataservices-api/teams","hooks_url":"https://api.github.com/repos/CartoDB/dataservices-api/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/dataservices-api/events","assignees_url":"https://api.github.com/repos/CartoDB/dataservices-api/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/dataservices-api/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/dataservices-api/tags","blobs_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/dataservices-api/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/dataservices-api/languages","stargazers_url":"https://api.github.com/repos/CartoDB/dataservices-api/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/dataservices-api/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/dataservices-api/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/dataservices-api/subscription","commits_url":"https://api.github.com/repos/CartoDB/dataservices-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/dataservices-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/dataservices-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/dataservices-api/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/dataservices-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/dataservices-api/merges","archive_url":"https://api.github.com/repos/CartoDB/dataservices-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/dataservices-api/downloads","issues_url":"https://api.github.com/repos/CartoDB/dataservices-api/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/dataservices-api/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/dataservices-api/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/dataservices-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/dataservices-api/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/dataservices-api/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/dataservices-api/deployments","created_at":"2015-11-03T10:05:38Z","updated_at":"2016-02-16T13:37:47Z","pushed_at":"2016-03-11T17:21:01Z","git_url":"git://github.com/CartoDB/dataservices-api.git","ssh_url":"git@github.com:CartoDB/dataservices-api.git","clone_url":"https://github.com/CartoDB/dataservices-api.git","svn_url":"https://github.com/CartoDB/dataservices-api","homepage":null,"size":469,"stargazers_count":2,"watchers_count":2,"language":"PLpgSQL","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":16,"forks":1,"open_issues":16,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110"},"html":{"href":"https://github.com/CartoDB/dataservices-api/pull/110"},"issue":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/issues/110"},"comments":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/issues/110/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/pulls/110/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/dataservices-api/statuses/4f3f9bd24765940ecf0cbb70e4c13429d4d68481"}}}}