{"action":"created","comment":{"url":"https://api.github.com/repos/reddit/baseplate/pulls/comments/60113830","id":60113830,"diff_hunk":"@@ -0,0 +1,72 @@\n+from __future__ import absolute_import\n+from __future__ import division\n+from __future__ import print_function\n+from __future__ import unicode_literals\n+\n+import itertools\n+import unittest\n+\n+from baseplate.retry import (\n+    ExponentialBackoffRetryPolicy,\n+    IndefiniteRetryPolicy,\n+    MaximumAttemptsRetryPolicy,\n+    TimeBudgetRetryPolicy,\n+)\n+\n+from .. import mock\n+\n+\n+class RetryPolicyTests(unittest.TestCase):\n+    def test_maximum_attempts(self):\n+        base_policy = mock.MagicMock()\n+        base_policy.__iter__.return_value = itertools.repeat(1.2)","path":"tests/unit/retry_tests.py","position":22,"original_position":22,"commit_id":"35289acfa13266f9426a3254beede945e8e7ab8e","original_commit_id":"35289acfa13266f9426a3254beede945e8e7ab8e","user":{"login":"spladug","id":338853,"avatar_url":"https://avatars.githubusercontent.com/u/338853?v=3","gravatar_id":"","url":"https://api.github.com/users/spladug","html_url":"https://github.com/spladug","followers_url":"https://api.github.com/users/spladug/followers","following_url":"https://api.github.com/users/spladug/following{/other_user}","gists_url":"https://api.github.com/users/spladug/gists{/gist_id}","starred_url":"https://api.github.com/users/spladug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spladug/subscriptions","organizations_url":"https://api.github.com/users/spladug/orgs","repos_url":"https://api.github.com/users/spladug/repos","events_url":"https://api.github.com/users/spladug/events{/privacy}","received_events_url":"https://api.github.com/users/spladug/received_events","type":"User","site_admin":false},"body":"Nope. Just wanted to see a value make it through.","created_at":"2016-04-18T18:53:11Z","updated_at":"2016-04-18T18:53:11Z","html_url":"https://github.com/reddit/baseplate/pull/31#discussion_r60113830","pull_request_url":"https://api.github.com/repos/reddit/baseplate/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/comments/60113830"},"html":{"href":"https://github.com/reddit/baseplate/pull/31#discussion_r60113830"},"pull_request":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/reddit/baseplate/pulls/31","id":66795168,"html_url":"https://github.com/reddit/baseplate/pull/31","diff_url":"https://github.com/reddit/baseplate/pull/31.diff","patch_url":"https://github.com/reddit/baseplate/pull/31.patch","issue_url":"https://api.github.com/repos/reddit/baseplate/issues/31","number":31,"state":"open","locked":false,"title":"Retries!","user":{"login":"spladug","id":338853,"avatar_url":"https://avatars.githubusercontent.com/u/338853?v=3","gravatar_id":"","url":"https://api.github.com/users/spladug","html_url":"https://github.com/spladug","followers_url":"https://api.github.com/users/spladug/followers","following_url":"https://api.github.com/users/spladug/following{/other_user}","gists_url":"https://api.github.com/users/spladug/gists{/gist_id}","starred_url":"https://api.github.com/users/spladug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spladug/subscriptions","organizations_url":"https://api.github.com/users/spladug/orgs","repos_url":"https://api.github.com/users/spladug/repos","events_url":"https://api.github.com/users/spladug/events{/privacy}","received_events_url":"https://api.github.com/users/spladug/received_events","type":"User","site_admin":false},"body":"There are two big things going on here: the `baseplate.retry` module and then the sugar in `baseplate.context.thrift`. \r\n\r\nThe `baseplate.retry` module is a low-level library with \"guts exposed\". It provides common retry policies in a composable manner. That commit also refactors several places inside baseplate which did their own retry logic to use this module. \r\n\r\nThe second part, in `baseplate.context.thrift`, adds some syntactic sugar to the thrift client. By default, the client will continue to do no retries (a policy of `attempts=1`) on remote operations because it cannot know if the operation being done is idempotent or not. The new sugar adds a context manager that allows a retry policy to be applied to service calls made within a `with` statement.\r\n\r\n```python\r\nwith context.activity_service.retrying(attempts=3) as activity_service:\r\n    return activity_service.count_activity(sr._fullname)\r\n```\r\n\r\nI looked at a bunch of prior art and tried various options before settling on this structure. I've written up [some documentation on my thoughts behind the API design](https://gist.github.com/spladug/dc587162fb718d8a9aca2b4eeeb6df69) in case it's helpful.\r\n\r\nI also restructured the exception hierarchy from the `thrift_pool` module. I'm taking the tack now that it shouldn't make its own exceptions as it's essentially acting as a \"missing piece\" from the thrift library itself and so it should integrate with that exception hierarchy properly instead. r2's currently the only user of this module and its use will not be broken by this change, though it could be scoped down further to prevent masking bugs down the line.\r\n\r\nThere are a couple of other commits here that do minor lint-related stuff that came up while working on this.\r\n\r\n:eyeglasses: @bsimpson63 @KeyserSosa @ckwang8128  ","created_at":"2016-04-18T03:37:52Z","updated_at":"2016-04-18T18:53:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d52ae42073a4febafbca920b3d174a757f04dba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/reddit/baseplate/pulls/31/commits","review_comments_url":"https://api.github.com/repos/reddit/baseplate/pulls/31/comments","review_comment_url":"https://api.github.com/repos/reddit/baseplate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/reddit/baseplate/issues/31/comments","statuses_url":"https://api.github.com/repos/reddit/baseplate/statuses/35289acfa13266f9426a3254beede945e8e7ab8e","head":{"label":"reddit:retries","ref":"retries","sha":"35289acfa13266f9426a3254beede945e8e7ab8e","user":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"repo":{"id":44694978,"name":"baseplate","full_name":"reddit/baseplate","owner":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/reddit/baseplate","description":"something to build on","fork":false,"url":"https://api.github.com/repos/reddit/baseplate","forks_url":"https://api.github.com/repos/reddit/baseplate/forks","keys_url":"https://api.github.com/repos/reddit/baseplate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reddit/baseplate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reddit/baseplate/teams","hooks_url":"https://api.github.com/repos/reddit/baseplate/hooks","issue_events_url":"https://api.github.com/repos/reddit/baseplate/issues/events{/number}","events_url":"https://api.github.com/repos/reddit/baseplate/events","assignees_url":"https://api.github.com/repos/reddit/baseplate/assignees{/user}","branches_url":"https://api.github.com/repos/reddit/baseplate/branches{/branch}","tags_url":"https://api.github.com/repos/reddit/baseplate/tags","blobs_url":"https://api.github.com/repos/reddit/baseplate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reddit/baseplate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reddit/baseplate/git/refs{/sha}","trees_url":"https://api.github.com/repos/reddit/baseplate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reddit/baseplate/statuses/{sha}","languages_url":"https://api.github.com/repos/reddit/baseplate/languages","stargazers_url":"https://api.github.com/repos/reddit/baseplate/stargazers","contributors_url":"https://api.github.com/repos/reddit/baseplate/contributors","subscribers_url":"https://api.github.com/repos/reddit/baseplate/subscribers","subscription_url":"https://api.github.com/repos/reddit/baseplate/subscription","commits_url":"https://api.github.com/repos/reddit/baseplate/commits{/sha}","git_commits_url":"https://api.github.com/repos/reddit/baseplate/git/commits{/sha}","comments_url":"https://api.github.com/repos/reddit/baseplate/comments{/number}","issue_comment_url":"https://api.github.com/repos/reddit/baseplate/issues/comments{/number}","contents_url":"https://api.github.com/repos/reddit/baseplate/contents/{+path}","compare_url":"https://api.github.com/repos/reddit/baseplate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reddit/baseplate/merges","archive_url":"https://api.github.com/repos/reddit/baseplate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reddit/baseplate/downloads","issues_url":"https://api.github.com/repos/reddit/baseplate/issues{/number}","pulls_url":"https://api.github.com/repos/reddit/baseplate/pulls{/number}","milestones_url":"https://api.github.com/repos/reddit/baseplate/milestones{/number}","notifications_url":"https://api.github.com/repos/reddit/baseplate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reddit/baseplate/labels{/name}","releases_url":"https://api.github.com/repos/reddit/baseplate/releases{/id}","deployments_url":"https://api.github.com/repos/reddit/baseplate/deployments","created_at":"2015-10-21T18:07:55Z","updated_at":"2016-04-06T15:54:36Z","pushed_at":"2016-04-18T03:37:53Z","git_url":"git://github.com/reddit/baseplate.git","ssh_url":"git@github.com:reddit/baseplate.git","clone_url":"https://github.com/reddit/baseplate.git","svn_url":"https://github.com/reddit/baseplate","homepage":"https://reddit.github.io/baseplate/","size":678,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":7,"forks":6,"open_issues":7,"watchers":5,"default_branch":"master"}},"base":{"label":"reddit:master","ref":"master","sha":"d7cca431d7acc4e72c1351465434e696c8057191","user":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"repo":{"id":44694978,"name":"baseplate","full_name":"reddit/baseplate","owner":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/reddit/baseplate","description":"something to build on","fork":false,"url":"https://api.github.com/repos/reddit/baseplate","forks_url":"https://api.github.com/repos/reddit/baseplate/forks","keys_url":"https://api.github.com/repos/reddit/baseplate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reddit/baseplate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reddit/baseplate/teams","hooks_url":"https://api.github.com/repos/reddit/baseplate/hooks","issue_events_url":"https://api.github.com/repos/reddit/baseplate/issues/events{/number}","events_url":"https://api.github.com/repos/reddit/baseplate/events","assignees_url":"https://api.github.com/repos/reddit/baseplate/assignees{/user}","branches_url":"https://api.github.com/repos/reddit/baseplate/branches{/branch}","tags_url":"https://api.github.com/repos/reddit/baseplate/tags","blobs_url":"https://api.github.com/repos/reddit/baseplate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reddit/baseplate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reddit/baseplate/git/refs{/sha}","trees_url":"https://api.github.com/repos/reddit/baseplate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reddit/baseplate/statuses/{sha}","languages_url":"https://api.github.com/repos/reddit/baseplate/languages","stargazers_url":"https://api.github.com/repos/reddit/baseplate/stargazers","contributors_url":"https://api.github.com/repos/reddit/baseplate/contributors","subscribers_url":"https://api.github.com/repos/reddit/baseplate/subscribers","subscription_url":"https://api.github.com/repos/reddit/baseplate/subscription","commits_url":"https://api.github.com/repos/reddit/baseplate/commits{/sha}","git_commits_url":"https://api.github.com/repos/reddit/baseplate/git/commits{/sha}","comments_url":"https://api.github.com/repos/reddit/baseplate/comments{/number}","issue_comment_url":"https://api.github.com/repos/reddit/baseplate/issues/comments{/number}","contents_url":"https://api.github.com/repos/reddit/baseplate/contents/{+path}","compare_url":"https://api.github.com/repos/reddit/baseplate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reddit/baseplate/merges","archive_url":"https://api.github.com/repos/reddit/baseplate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reddit/baseplate/downloads","issues_url":"https://api.github.com/repos/reddit/baseplate/issues{/number}","pulls_url":"https://api.github.com/repos/reddit/baseplate/pulls{/number}","milestones_url":"https://api.github.com/repos/reddit/baseplate/milestones{/number}","notifications_url":"https://api.github.com/repos/reddit/baseplate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reddit/baseplate/labels{/name}","releases_url":"https://api.github.com/repos/reddit/baseplate/releases{/id}","deployments_url":"https://api.github.com/repos/reddit/baseplate/deployments","created_at":"2015-10-21T18:07:55Z","updated_at":"2016-04-06T15:54:36Z","pushed_at":"2016-04-18T03:37:53Z","git_url":"git://github.com/reddit/baseplate.git","ssh_url":"git@github.com:reddit/baseplate.git","clone_url":"https://github.com/reddit/baseplate.git","svn_url":"https://github.com/reddit/baseplate","homepage":"https://reddit.github.io/baseplate/","size":678,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":7,"forks":6,"open_issues":7,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/31"},"html":{"href":"https://github.com/reddit/baseplate/pull/31"},"issue":{"href":"https://api.github.com/repos/reddit/baseplate/issues/31"},"comments":{"href":"https://api.github.com/repos/reddit/baseplate/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/reddit/baseplate/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/reddit/baseplate/statuses/35289acfa13266f9426a3254beede945e8e7ab8e"}}}}