{"action":"created","comment":{"url":"https://api.github.com/repos/Workiva/w_transport/pulls/comments/59289754","id":59289754,"diff_hunk":"@@ -170,18 +171,60 @@ class RetryBackOff {\n   /// The back-off method to use. One of none, fixed, or exponential.\n   final RetryBackOffMethod method;\n \n+  /// Whether to enable jitter or not.\n+  final bool enableJitter;\n+\n+  /// The maximum duration between retries.\n+  final maxDurationInMs;\n+\n+  /// The default maximum duration between retries. (5 minutes)\n+  static const defaultMaxDurationInMs = 5 * 60 * 1000;\n+\n+  int _baseBackOffFunction(int numAttempts) {\n+    return this.duration.inMilliseconds * pow(2, numAttempts);\n+  }\n+\n+  Duration calculate(int numAttempts) {\n+    Random random = new Random();\n+    if (enableJitter != null && enableJitter == true) {\n+      if (maxDurationInMs != null) {\n+        return new Duration(\n+            milliseconds: random.nextInt(\n+                min(this.maxDurationInMs, _baseBackOffFunction(numAttempts))));\n+      } else {\n+        return new Duration(\n+            milliseconds: random.nextInt(_baseBackOffFunction(numAttempts)));\n+      }\n+    } else {\n+      if (maxDurationInMs != null) {\n+        return new Duration(\n+            milliseconds:\n+                min(this.maxDurationInMs, _baseBackOffFunction(numAttempts)));\n+      } else {\n+        return new Duration(milliseconds: _baseBackOffFunction(numAttempts));\n+      }\n+    }\n+  }\n+\n   /// Construct a new exponential back-off representation where [duration] is\n   /// the base duration from which each delay will be calculated.\n-  const RetryBackOff.exponential(this.duration)\n-      : method = RetryBackOffMethod.exponential;\n+  const RetryBackOff.exponential(this.duration,\n+      {bool this.enableJitter, maxDurationInMs})\n+      : method = RetryBackOffMethod.exponential,\n+        maxDurationInMs = maxDurationInMs ?? defaultMaxDurationInMs;\n \n   /// Construct a new fixed back-off representation where [duration] is the\n   /// delay between each retry.\n-  const RetryBackOff.fixed(this.duration) : method = RetryBackOffMethod.fixed;\n+  const RetryBackOff.fixed(this.duration)","path":"lib/src/http/auto_retry.dart","position":59,"original_position":59,"commit_id":"add53d1e6a48135550ec9a9f9b03bd8ac26bb1e8","original_commit_id":"add53d1e6a48135550ec9a9f9b03bd8ac26bb1e8","user":{"login":"evanweible-wf","id":1738457,"avatar_url":"https://avatars.githubusercontent.com/u/1738457?v=3","gravatar_id":"","url":"https://api.github.com/users/evanweible-wf","html_url":"https://github.com/evanweible-wf","followers_url":"https://api.github.com/users/evanweible-wf/followers","following_url":"https://api.github.com/users/evanweible-wf/following{/other_user}","gists_url":"https://api.github.com/users/evanweible-wf/gists{/gist_id}","starred_url":"https://api.github.com/users/evanweible-wf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evanweible-wf/subscriptions","organizations_url":"https://api.github.com/users/evanweible-wf/orgs","repos_url":"https://api.github.com/users/evanweible-wf/repos","events_url":"https://api.github.com/users/evanweible-wf/events{/privacy}","received_events_url":"https://api.github.com/users/evanweible-wf/received_events","type":"User","site_admin":false},"body":"Jitter could be used even with a fixed backoff, couldn't it? Sure it wouldn't help much for a fixed backoff of 1 second, but it could make sense for larger intervals.","created_at":"2016-04-11T22:03:04Z","updated_at":"2016-04-11T22:03:04Z","html_url":"https://github.com/Workiva/w_transport/pull/133#discussion_r59289754","pull_request_url":"https://api.github.com/repos/Workiva/w_transport/pulls/133","_links":{"self":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/comments/59289754"},"html":{"href":"https://github.com/Workiva/w_transport/pull/133#discussion_r59289754"},"pull_request":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/133"}}},"pull_request":{"url":"https://api.github.com/repos/Workiva/w_transport/pulls/133","id":66039587,"html_url":"https://github.com/Workiva/w_transport/pull/133","diff_url":"https://github.com/Workiva/w_transport/pull/133.diff","patch_url":"https://github.com/Workiva/w_transport/pull/133.patch","issue_url":"https://api.github.com/repos/Workiva/w_transport/issues/133","number":133,"state":"open","locked":false,"title":"cp-1605 : added jitter and maxDuration between retries","user":{"login":"dustinlessard-wf","id":2326518,"avatar_url":"https://avatars.githubusercontent.com/u/2326518?v=3","gravatar_id":"","url":"https://api.github.com/users/dustinlessard-wf","html_url":"https://github.com/dustinlessard-wf","followers_url":"https://api.github.com/users/dustinlessard-wf/followers","following_url":"https://api.github.com/users/dustinlessard-wf/following{/other_user}","gists_url":"https://api.github.com/users/dustinlessard-wf/gists{/gist_id}","starred_url":"https://api.github.com/users/dustinlessard-wf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dustinlessard-wf/subscriptions","organizations_url":"https://api.github.com/users/dustinlessard-wf/orgs","repos_url":"https://api.github.com/users/dustinlessard-wf/repos","events_url":"https://api.github.com/users/dustinlessard-wf/events{/privacy}","received_events_url":"https://api.github.com/users/dustinlessard-wf/received_events","type":"User","site_admin":false},"body":"### CODE REVIEW\r\n\r\nFor consideration:\r\n\r\n#### PROBLEM\r\nWe don't currently allow jitter with our exponential backoff strategy.\r\n\r\n#### SOLUTION\r\nWe now allow the optional inclusion of jitter and a maximum retry duration + default maximum retry duration.\r\n\r\nInspired by https://www.awsarchitectureblog.com/2015/03/backoff.html\r\n\r\n**Testing Suggestions:**\r\nrun unit-tests\r\nrun integration tests\r\n\r\n**Required:**\r\n@evanweible-wf @maxwellpeterson-wf @trentgrover-wf\r\n\r\n**FYI:**\r\n@jayudey-wf","created_at":"2016-04-11T18:28:15Z","updated_at":"2016-04-11T22:03:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7e6e29d5bb50483e701ca383614dc89cbea0847","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Workiva/w_transport/pulls/133/commits","review_comments_url":"https://api.github.com/repos/Workiva/w_transport/pulls/133/comments","review_comment_url":"https://api.github.com/repos/Workiva/w_transport/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Workiva/w_transport/issues/133/comments","statuses_url":"https://api.github.com/repos/Workiva/w_transport/statuses/add53d1e6a48135550ec9a9f9b03bd8ac26bb1e8","head":{"label":"Workiva:cp-1605","ref":"cp-1605","sha":"add53d1e6a48135550ec9a9f9b03bd8ac26bb1e8","user":{"login":"Workiva","id":1087529,"avatar_url":"https://avatars.githubusercontent.com/u/1087529?v=3","gravatar_id":"","url":"https://api.github.com/users/Workiva","html_url":"https://github.com/Workiva","followers_url":"https://api.github.com/users/Workiva/followers","following_url":"https://api.github.com/users/Workiva/following{/other_user}","gists_url":"https://api.github.com/users/Workiva/gists{/gist_id}","starred_url":"https://api.github.com/users/Workiva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Workiva/subscriptions","organizations_url":"https://api.github.com/users/Workiva/orgs","repos_url":"https://api.github.com/users/Workiva/repos","events_url":"https://api.github.com/users/Workiva/events{/privacy}","received_events_url":"https://api.github.com/users/Workiva/received_events","type":"Organization","site_admin":false},"repo":{"id":32808289,"name":"w_transport","full_name":"Workiva/w_transport","owner":{"login":"Workiva","id":1087529,"avatar_url":"https://avatars.githubusercontent.com/u/1087529?v=3","gravatar_id":"","url":"https://api.github.com/users/Workiva","html_url":"https://github.com/Workiva","followers_url":"https://api.github.com/users/Workiva/followers","following_url":"https://api.github.com/users/Workiva/following{/other_user}","gists_url":"https://api.github.com/users/Workiva/gists{/gist_id}","starred_url":"https://api.github.com/users/Workiva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Workiva/subscriptions","organizations_url":"https://api.github.com/users/Workiva/orgs","repos_url":"https://api.github.com/users/Workiva/repos","events_url":"https://api.github.com/users/Workiva/events{/privacy}","received_events_url":"https://api.github.com/users/Workiva/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Workiva/w_transport","description":"","fork":false,"url":"https://api.github.com/repos/Workiva/w_transport","forks_url":"https://api.github.com/repos/Workiva/w_transport/forks","keys_url":"https://api.github.com/repos/Workiva/w_transport/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Workiva/w_transport/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Workiva/w_transport/teams","hooks_url":"https://api.github.com/repos/Workiva/w_transport/hooks","issue_events_url":"https://api.github.com/repos/Workiva/w_transport/issues/events{/number}","events_url":"https://api.github.com/repos/Workiva/w_transport/events","assignees_url":"https://api.github.com/repos/Workiva/w_transport/assignees{/user}","branches_url":"https://api.github.com/repos/Workiva/w_transport/branches{/branch}","tags_url":"https://api.github.com/repos/Workiva/w_transport/tags","blobs_url":"https://api.github.com/repos/Workiva/w_transport/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Workiva/w_transport/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Workiva/w_transport/git/refs{/sha}","trees_url":"https://api.github.com/repos/Workiva/w_transport/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Workiva/w_transport/statuses/{sha}","languages_url":"https://api.github.com/repos/Workiva/w_transport/languages","stargazers_url":"https://api.github.com/repos/Workiva/w_transport/stargazers","contributors_url":"https://api.github.com/repos/Workiva/w_transport/contributors","subscribers_url":"https://api.github.com/repos/Workiva/w_transport/subscribers","subscription_url":"https://api.github.com/repos/Workiva/w_transport/subscription","commits_url":"https://api.github.com/repos/Workiva/w_transport/commits{/sha}","git_commits_url":"https://api.github.com/repos/Workiva/w_transport/git/commits{/sha}","comments_url":"https://api.github.com/repos/Workiva/w_transport/comments{/number}","issue_comment_url":"https://api.github.com/repos/Workiva/w_transport/issues/comments{/number}","contents_url":"https://api.github.com/repos/Workiva/w_transport/contents/{+path}","compare_url":"https://api.github.com/repos/Workiva/w_transport/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Workiva/w_transport/merges","archive_url":"https://api.github.com/repos/Workiva/w_transport/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Workiva/w_transport/downloads","issues_url":"https://api.github.com/repos/Workiva/w_transport/issues{/number}","pulls_url":"https://api.github.com/repos/Workiva/w_transport/pulls{/number}","milestones_url":"https://api.github.com/repos/Workiva/w_transport/milestones{/number}","notifications_url":"https://api.github.com/repos/Workiva/w_transport/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Workiva/w_transport/labels{/name}","releases_url":"https://api.github.com/repos/Workiva/w_transport/releases{/id}","deployments_url":"https://api.github.com/repos/Workiva/w_transport/deployments","created_at":"2015-03-24T15:43:40Z","updated_at":"2016-03-22T13:35:12Z","pushed_at":"2016-04-11T19:27:31Z","git_url":"git://github.com/Workiva/w_transport.git","ssh_url":"git@github.com:Workiva/w_transport.git","clone_url":"https://github.com/Workiva/w_transport.git","svn_url":"https://github.com/Workiva/w_transport","homepage":null,"size":771,"stargazers_count":7,"watchers_count":7,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":10,"forks":2,"open_issues":10,"watchers":7,"default_branch":"master"}},"base":{"label":"Workiva:master","ref":"master","sha":"91855c11db799e7b5b5715a07680fff9195a3572","user":{"login":"Workiva","id":1087529,"avatar_url":"https://avatars.githubusercontent.com/u/1087529?v=3","gravatar_id":"","url":"https://api.github.com/users/Workiva","html_url":"https://github.com/Workiva","followers_url":"https://api.github.com/users/Workiva/followers","following_url":"https://api.github.com/users/Workiva/following{/other_user}","gists_url":"https://api.github.com/users/Workiva/gists{/gist_id}","starred_url":"https://api.github.com/users/Workiva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Workiva/subscriptions","organizations_url":"https://api.github.com/users/Workiva/orgs","repos_url":"https://api.github.com/users/Workiva/repos","events_url":"https://api.github.com/users/Workiva/events{/privacy}","received_events_url":"https://api.github.com/users/Workiva/received_events","type":"Organization","site_admin":false},"repo":{"id":32808289,"name":"w_transport","full_name":"Workiva/w_transport","owner":{"login":"Workiva","id":1087529,"avatar_url":"https://avatars.githubusercontent.com/u/1087529?v=3","gravatar_id":"","url":"https://api.github.com/users/Workiva","html_url":"https://github.com/Workiva","followers_url":"https://api.github.com/users/Workiva/followers","following_url":"https://api.github.com/users/Workiva/following{/other_user}","gists_url":"https://api.github.com/users/Workiva/gists{/gist_id}","starred_url":"https://api.github.com/users/Workiva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Workiva/subscriptions","organizations_url":"https://api.github.com/users/Workiva/orgs","repos_url":"https://api.github.com/users/Workiva/repos","events_url":"https://api.github.com/users/Workiva/events{/privacy}","received_events_url":"https://api.github.com/users/Workiva/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Workiva/w_transport","description":"","fork":false,"url":"https://api.github.com/repos/Workiva/w_transport","forks_url":"https://api.github.com/repos/Workiva/w_transport/forks","keys_url":"https://api.github.com/repos/Workiva/w_transport/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Workiva/w_transport/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Workiva/w_transport/teams","hooks_url":"https://api.github.com/repos/Workiva/w_transport/hooks","issue_events_url":"https://api.github.com/repos/Workiva/w_transport/issues/events{/number}","events_url":"https://api.github.com/repos/Workiva/w_transport/events","assignees_url":"https://api.github.com/repos/Workiva/w_transport/assignees{/user}","branches_url":"https://api.github.com/repos/Workiva/w_transport/branches{/branch}","tags_url":"https://api.github.com/repos/Workiva/w_transport/tags","blobs_url":"https://api.github.com/repos/Workiva/w_transport/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Workiva/w_transport/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Workiva/w_transport/git/refs{/sha}","trees_url":"https://api.github.com/repos/Workiva/w_transport/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Workiva/w_transport/statuses/{sha}","languages_url":"https://api.github.com/repos/Workiva/w_transport/languages","stargazers_url":"https://api.github.com/repos/Workiva/w_transport/stargazers","contributors_url":"https://api.github.com/repos/Workiva/w_transport/contributors","subscribers_url":"https://api.github.com/repos/Workiva/w_transport/subscribers","subscription_url":"https://api.github.com/repos/Workiva/w_transport/subscription","commits_url":"https://api.github.com/repos/Workiva/w_transport/commits{/sha}","git_commits_url":"https://api.github.com/repos/Workiva/w_transport/git/commits{/sha}","comments_url":"https://api.github.com/repos/Workiva/w_transport/comments{/number}","issue_comment_url":"https://api.github.com/repos/Workiva/w_transport/issues/comments{/number}","contents_url":"https://api.github.com/repos/Workiva/w_transport/contents/{+path}","compare_url":"https://api.github.com/repos/Workiva/w_transport/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Workiva/w_transport/merges","archive_url":"https://api.github.com/repos/Workiva/w_transport/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Workiva/w_transport/downloads","issues_url":"https://api.github.com/repos/Workiva/w_transport/issues{/number}","pulls_url":"https://api.github.com/repos/Workiva/w_transport/pulls{/number}","milestones_url":"https://api.github.com/repos/Workiva/w_transport/milestones{/number}","notifications_url":"https://api.github.com/repos/Workiva/w_transport/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Workiva/w_transport/labels{/name}","releases_url":"https://api.github.com/repos/Workiva/w_transport/releases{/id}","deployments_url":"https://api.github.com/repos/Workiva/w_transport/deployments","created_at":"2015-03-24T15:43:40Z","updated_at":"2016-03-22T13:35:12Z","pushed_at":"2016-04-11T19:27:31Z","git_url":"git://github.com/Workiva/w_transport.git","ssh_url":"git@github.com:Workiva/w_transport.git","clone_url":"https://github.com/Workiva/w_transport.git","svn_url":"https://github.com/Workiva/w_transport","homepage":null,"size":771,"stargazers_count":7,"watchers_count":7,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":10,"forks":2,"open_issues":10,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/133"},"html":{"href":"https://github.com/Workiva/w_transport/pull/133"},"issue":{"href":"https://api.github.com/repos/Workiva/w_transport/issues/133"},"comments":{"href":"https://api.github.com/repos/Workiva/w_transport/issues/133/comments"},"review_comments":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/133/comments"},"review_comment":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Workiva/w_transport/pulls/133/commits"},"statuses":{"href":"https://api.github.com/repos/Workiva/w_transport/statuses/add53d1e6a48135550ec9a9f9b03bd8ac26bb1e8"}}}}