{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/comments/47270329","id":47270329,"diff_hunk":"@@ -0,0 +1,19 @@\n+from datetime import datetime, timedelta\n+from dimagi.utils.rate_limit import rate_limit\n+from django.test import SimpleTestCase\n+\n+\n+class RateLimitTestCase(SimpleTestCase):\n+    def test_rate_limit(self):\n+        start = datetime.utcnow()\n+        rate_limit_count = 0\n+        iteration_count = 0\n+\n+        while (datetime.utcnow() - start) < timedelta(seconds=18):\n+            # Only allow 10 actions every 5 seconds in an 18 second period of time\n+            if rate_limit('rate-limit-test', actions_allowed=10, how_often=5):\n+                rate_limit_count += 1\n+            iteration_count += 1","path":"dimagi/utils/tests/test_rate_limit.py","position":16,"original_position":16,"commit_id":"75df3c2042d6a12a400868a9b7eef7617540279e","original_commit_id":"75df3c2042d6a12a400868a9b7eef7617540279e","user":{"login":"millerdev","id":464726,"avatar_url":"https://avatars.githubusercontent.com/u/464726?v=3","gravatar_id":"","url":"https://api.github.com/users/millerdev","html_url":"https://github.com/millerdev","followers_url":"https://api.github.com/users/millerdev/followers","following_url":"https://api.github.com/users/millerdev/following{/other_user}","gists_url":"https://api.github.com/users/millerdev/gists{/gist_id}","starred_url":"https://api.github.com/users/millerdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/millerdev/subscriptions","organizations_url":"https://api.github.com/users/millerdev/orgs","repos_url":"https://api.github.com/users/millerdev/repos","events_url":"https://api.github.com/users/millerdev/events{/privacy}","received_events_url":"https://api.github.com/users/millerdev/received_events","type":"User","site_admin":false},"body":"Does this loop run for 18 seconds when running tests?","created_at":"2015-12-10T19:14:00Z","updated_at":"2015-12-10T19:14:00Z","html_url":"https://github.com/dimagi/dimagi-utils/pull/339#discussion_r47270329","pull_request_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339","_links":{"self":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/comments/47270329"},"html":{"href":"https://github.com/dimagi/dimagi-utils/pull/339#discussion_r47270329"},"pull_request":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339","id":53182504,"html_url":"https://github.com/dimagi/dimagi-utils/pull/339","diff_url":"https://github.com/dimagi/dimagi-utils/pull/339.diff","patch_url":"https://github.com/dimagi/dimagi-utils/pull/339.patch","issue_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/339","number":339,"state":"closed","locked":false,"title":"Add simple rate limiting util","user":{"login":"gcapalbo","id":1028814,"avatar_url":"https://avatars.githubusercontent.com/u/1028814?v=3","gravatar_id":"","url":"https://api.github.com/users/gcapalbo","html_url":"https://github.com/gcapalbo","followers_url":"https://api.github.com/users/gcapalbo/followers","following_url":"https://api.github.com/users/gcapalbo/following{/other_user}","gists_url":"https://api.github.com/users/gcapalbo/gists{/gist_id}","starred_url":"https://api.github.com/users/gcapalbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gcapalbo/subscriptions","organizations_url":"https://api.github.com/users/gcapalbo/orgs","repos_url":"https://api.github.com/users/gcapalbo/repos","events_url":"https://api.github.com/users/gcapalbo/events{/privacy}","received_events_url":"https://api.github.com/users/gcapalbo/received_events","type":"User","site_admin":false},"body":"@calellowitz ","created_at":"2015-12-09T21:45:26Z","updated_at":"2015-12-10T19:14:00Z","closed_at":"2015-12-10T15:06:47Z","merged_at":"2015-12-10T15:06:47Z","merge_commit_sha":"a7a1ec572e5c3a307e93c6472263cd94bab7074a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339/commits","review_comments_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339/comments","review_comment_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/339/comments","statuses_url":"https://api.github.com/repos/dimagi/dimagi-utils/statuses/75df3c2042d6a12a400868a9b7eef7617540279e","head":{"label":"dimagi:rate-limit-util","ref":"rate-limit-util","sha":"75df3c2042d6a12a400868a9b7eef7617540279e","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":902016,"name":"dimagi-utils","full_name":"dimagi/dimagi-utils","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/dimagi-utils","description":"Shared utility code used @ Dimagi","fork":false,"url":"https://api.github.com/repos/dimagi/dimagi-utils","forks_url":"https://api.github.com/repos/dimagi/dimagi-utils/forks","keys_url":"https://api.github.com/repos/dimagi/dimagi-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/dimagi-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/dimagi-utils/teams","hooks_url":"https://api.github.com/repos/dimagi/dimagi-utils/hooks","issue_events_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/dimagi-utils/events","assignees_url":"https://api.github.com/repos/dimagi/dimagi-utils/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/dimagi-utils/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/dimagi-utils/tags","blobs_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/dimagi-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/dimagi-utils/languages","stargazers_url":"https://api.github.com/repos/dimagi/dimagi-utils/stargazers","contributors_url":"https://api.github.com/repos/dimagi/dimagi-utils/contributors","subscribers_url":"https://api.github.com/repos/dimagi/dimagi-utils/subscribers","subscription_url":"https://api.github.com/repos/dimagi/dimagi-utils/subscription","commits_url":"https://api.github.com/repos/dimagi/dimagi-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/dimagi-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/dimagi-utils/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/dimagi-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/dimagi-utils/merges","archive_url":"https://api.github.com/repos/dimagi/dimagi-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/dimagi-utils/downloads","issues_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/dimagi-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/dimagi-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/dimagi-utils/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/dimagi-utils/releases{/id}","created_at":"2010-09-10T18:48:37Z","updated_at":"2015-05-06T14:39:05Z","pushed_at":"2015-12-10T16:24:34Z","git_url":"git://github.com/dimagi/dimagi-utils.git","ssh_url":"git@github.com:dimagi/dimagi-utils.git","clone_url":"https://github.com/dimagi/dimagi-utils.git","svn_url":"https://github.com/dimagi/dimagi-utils","homepage":"http://www.dimagi.com","size":943,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":4,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"7fa55d367e9f5ef9e57ef7e58515a25c2eee7794","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":902016,"name":"dimagi-utils","full_name":"dimagi/dimagi-utils","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/dimagi-utils","description":"Shared utility code used @ Dimagi","fork":false,"url":"https://api.github.com/repos/dimagi/dimagi-utils","forks_url":"https://api.github.com/repos/dimagi/dimagi-utils/forks","keys_url":"https://api.github.com/repos/dimagi/dimagi-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/dimagi-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/dimagi-utils/teams","hooks_url":"https://api.github.com/repos/dimagi/dimagi-utils/hooks","issue_events_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/dimagi-utils/events","assignees_url":"https://api.github.com/repos/dimagi/dimagi-utils/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/dimagi-utils/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/dimagi-utils/tags","blobs_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/dimagi-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/dimagi-utils/languages","stargazers_url":"https://api.github.com/repos/dimagi/dimagi-utils/stargazers","contributors_url":"https://api.github.com/repos/dimagi/dimagi-utils/contributors","subscribers_url":"https://api.github.com/repos/dimagi/dimagi-utils/subscribers","subscription_url":"https://api.github.com/repos/dimagi/dimagi-utils/subscription","commits_url":"https://api.github.com/repos/dimagi/dimagi-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/dimagi-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/dimagi-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/dimagi-utils/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/dimagi-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/dimagi-utils/merges","archive_url":"https://api.github.com/repos/dimagi/dimagi-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/dimagi-utils/downloads","issues_url":"https://api.github.com/repos/dimagi/dimagi-utils/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/dimagi-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/dimagi-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/dimagi-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/dimagi-utils/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/dimagi-utils/releases{/id}","created_at":"2010-09-10T18:48:37Z","updated_at":"2015-05-06T14:39:05Z","pushed_at":"2015-12-10T16:24:34Z","git_url":"git://github.com/dimagi/dimagi-utils.git","ssh_url":"git@github.com:dimagi/dimagi-utils.git","clone_url":"https://github.com/dimagi/dimagi-utils.git","svn_url":"https://github.com/dimagi/dimagi-utils","homepage":"http://www.dimagi.com","size":943,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339"},"html":{"href":"https://github.com/dimagi/dimagi-utils/pull/339"},"issue":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/issues/339"},"comments":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/issues/339/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/pulls/339/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/dimagi-utils/statuses/75df3c2042d6a12a400868a9b7eef7617540279e"}}}}