{"action":"created","comment":{"url":"https://api.github.com/repos/Tapjoy/chore/pulls/comments/57189105","id":57189105,"diff_hunk":"@@ -11,27 +11,27 @@ def initialize(size)\n         @size = size\n         @batch = []\n         @mutex = Mutex.new\n-        @last_message = nil\n         @callback = nil\n         @running = true\n       end\n \n       # The main entry point of the Batcher, <tt>schedule</tt> begins a thread with the provided +batch_timeout+ \n       # as the only argument. While the Batcher is running, it will attempt to check if either the batch is full, \n-      # or if the +batch_timeout+ has elapsed since the last batch was executed. If the batch is full, it will be executed.\n-      # If the +batch_timeout+ has elapsed, as soon as the next message enters the batch, it will be executed.\n+      # or if the +batch_timeout+ has elapsed since the oldest message was added. If either case is true, the\n+      # items in the batch will be executed.\n       # \n       # Calling <tt>stop</tt> will cause the thread to finish it's current check, and exit\n-      def schedule(batch_timeout=20)\n+      def schedule(batch_timeout)\n         @thread = Thread.new(batch_timeout) do |timeout|\n           Chore.logger.info \"Batching timeout thread starting\"\n           while @running do\n             begin \n-              Chore.logger.debug \"Last message added to batch: #{@last_message}: #{@batch.size}\"\n-              if @last_message && Time.now > (@last_message + timeout)\n-                Chore.logger.debug \"Batching timeout reached (#{@last_message + timeout}), current size: #{@batch.size}\"\n+              oldest_item = @batch.first\n+              timestamp = oldest_item && oldest_item.created_at\n+              Chore.logger.debug \"Oldest message in batch: #{timestamp}, size: #{@batch.size}\"\n+              if timestamp && Time.now > (timestamp + timeout)\n+                Chore.logger.debug \"Batching timeout reached (#{timestamp + timeout}), current size: #{@batch.size}\"","path":"lib/chore/strategies/consumer/batcher.rb","position":30,"original_position":30,"commit_id":"51aa3c1b29c1a0d00b19bbe6109975fb43df4b00","original_commit_id":"51aa3c1b29c1a0d00b19bbe6109975fb43df4b00","user":{"login":"obrie","id":6991,"avatar_url":"https://avatars.githubusercontent.com/u/6991?v=3","gravatar_id":"","url":"https://api.github.com/users/obrie","html_url":"https://github.com/obrie","followers_url":"https://api.github.com/users/obrie/followers","following_url":"https://api.github.com/users/obrie/following{/other_user}","gists_url":"https://api.github.com/users/obrie/gists{/gist_id}","starred_url":"https://api.github.com/users/obrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obrie/subscriptions","organizations_url":"https://api.github.com/users/obrie/orgs","repos_url":"https://api.github.com/users/obrie/repos","events_url":"https://api.github.com/users/obrie/events{/privacy}","received_events_url":"https://api.github.com/users/obrie/received_events","type":"User","site_admin":false},"body":"That doesn't work because `timestamp` is based on `oldest_item`.  Also, I've gotten the exact opposite feedback from other people in the past who don't like inline assignment in `if` statements so I tend to avoid it in more complex statements like this :)","created_at":"2016-03-23T16:17:34Z","updated_at":"2016-03-23T16:17:34Z","html_url":"https://github.com/Tapjoy/chore/pull/30#discussion_r57189105","pull_request_url":"https://api.github.com/repos/Tapjoy/chore/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/comments/57189105"},"html":{"href":"https://github.com/Tapjoy/chore/pull/30#discussion_r57189105"},"pull_request":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/Tapjoy/chore/pulls/30","id":63905018,"html_url":"https://github.com/Tapjoy/chore/pull/30","diff_url":"https://github.com/Tapjoy/chore/pull/30.diff","patch_url":"https://github.com/Tapjoy/chore/pull/30.patch","issue_url":"https://api.github.com/repos/Tapjoy/chore/issues/30","number":30,"state":"open","locked":false,"title":"Change batch timeouts to be both configurable and based on the time oldest message","user":{"login":"obrie","id":6991,"avatar_url":"https://avatars.githubusercontent.com/u/6991?v=3","gravatar_id":"","url":"https://api.github.com/users/obrie","html_url":"https://github.com/obrie","followers_url":"https://api.github.com/users/obrie/followers","following_url":"https://api.github.com/users/obrie/following{/other_user}","gists_url":"https://api.github.com/users/obrie/gists{/gist_id}","starred_url":"https://api.github.com/users/obrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obrie/subscriptions","organizations_url":"https://api.github.com/users/obrie/orgs","repos_url":"https://api.github.com/users/obrie/repos","events_url":"https://api.github.com/users/obrie/events{/privacy}","received_events_url":"https://api.github.com/users/obrie/received_events","type":"User","site_admin":false},"body":"This makes two changes:\r\n1. The batch timeouts are now configurable instead of being hard-coded to 20s\r\n2. We now run `execute` when the oldest message in the batcher has exceeded the timeout.\r\n\r\nTo provide a little context, the current behavior of the timeout is that it is based on the newest message in the batcher.  Consider the scenario where batch size = 10 and timeout = 1m.  If a message came in every 30s, then the batch wouldn't be processed until 5m has passed (because the batch size will then be 10).\r\n\r\nThis still needs to be tested.  I will also be looking for feedback / guidance on whether this should be a minor or major rev change.\r\n\r\n/to @gregorysabatino @theo-lanman @StabbyCutyou ","created_at":"2016-03-23T15:51:49Z","updated_at":"2016-03-23T16:17:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2da9cafc19c452e2070e7e5f67ed5b2b92f693f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Tapjoy/chore/pulls/30/commits","review_comments_url":"https://api.github.com/repos/Tapjoy/chore/pulls/30/comments","review_comment_url":"https://api.github.com/repos/Tapjoy/chore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Tapjoy/chore/issues/30/comments","statuses_url":"https://api.github.com/repos/Tapjoy/chore/statuses/51aa3c1b29c1a0d00b19bbe6109975fb43df4b00","head":{"label":"Tapjoy:fix/batcher_timeouts","ref":"fix/batcher_timeouts","sha":"51aa3c1b29c1a0d00b19bbe6109975fb43df4b00","user":{"login":"Tapjoy","id":716849,"avatar_url":"https://avatars.githubusercontent.com/u/716849?v=3","gravatar_id":"","url":"https://api.github.com/users/Tapjoy","html_url":"https://github.com/Tapjoy","followers_url":"https://api.github.com/users/Tapjoy/followers","following_url":"https://api.github.com/users/Tapjoy/following{/other_user}","gists_url":"https://api.github.com/users/Tapjoy/gists{/gist_id}","starred_url":"https://api.github.com/users/Tapjoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tapjoy/subscriptions","organizations_url":"https://api.github.com/users/Tapjoy/orgs","repos_url":"https://api.github.com/users/Tapjoy/repos","events_url":"https://api.github.com/users/Tapjoy/events{/privacy}","received_events_url":"https://api.github.com/users/Tapjoy/received_events","type":"Organization","site_admin":false},"repo":{"id":24512598,"name":"chore","full_name":"Tapjoy/chore","owner":{"login":"Tapjoy","id":716849,"avatar_url":"https://avatars.githubusercontent.com/u/716849?v=3","gravatar_id":"","url":"https://api.github.com/users/Tapjoy","html_url":"https://github.com/Tapjoy","followers_url":"https://api.github.com/users/Tapjoy/followers","following_url":"https://api.github.com/users/Tapjoy/following{/other_user}","gists_url":"https://api.github.com/users/Tapjoy/gists{/gist_id}","starred_url":"https://api.github.com/users/Tapjoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tapjoy/subscriptions","organizations_url":"https://api.github.com/users/Tapjoy/orgs","repos_url":"https://api.github.com/users/Tapjoy/repos","events_url":"https://api.github.com/users/Tapjoy/events{/privacy}","received_events_url":"https://api.github.com/users/Tapjoy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tapjoy/chore","description":"Job processing...for the future!","fork":false,"url":"https://api.github.com/repos/Tapjoy/chore","forks_url":"https://api.github.com/repos/Tapjoy/chore/forks","keys_url":"https://api.github.com/repos/Tapjoy/chore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tapjoy/chore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tapjoy/chore/teams","hooks_url":"https://api.github.com/repos/Tapjoy/chore/hooks","issue_events_url":"https://api.github.com/repos/Tapjoy/chore/issues/events{/number}","events_url":"https://api.github.com/repos/Tapjoy/chore/events","assignees_url":"https://api.github.com/repos/Tapjoy/chore/assignees{/user}","branches_url":"https://api.github.com/repos/Tapjoy/chore/branches{/branch}","tags_url":"https://api.github.com/repos/Tapjoy/chore/tags","blobs_url":"https://api.github.com/repos/Tapjoy/chore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tapjoy/chore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tapjoy/chore/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tapjoy/chore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tapjoy/chore/statuses/{sha}","languages_url":"https://api.github.com/repos/Tapjoy/chore/languages","stargazers_url":"https://api.github.com/repos/Tapjoy/chore/stargazers","contributors_url":"https://api.github.com/repos/Tapjoy/chore/contributors","subscribers_url":"https://api.github.com/repos/Tapjoy/chore/subscribers","subscription_url":"https://api.github.com/repos/Tapjoy/chore/subscription","commits_url":"https://api.github.com/repos/Tapjoy/chore/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tapjoy/chore/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tapjoy/chore/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tapjoy/chore/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tapjoy/chore/contents/{+path}","compare_url":"https://api.github.com/repos/Tapjoy/chore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tapjoy/chore/merges","archive_url":"https://api.github.com/repos/Tapjoy/chore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tapjoy/chore/downloads","issues_url":"https://api.github.com/repos/Tapjoy/chore/issues{/number}","pulls_url":"https://api.github.com/repos/Tapjoy/chore/pulls{/number}","milestones_url":"https://api.github.com/repos/Tapjoy/chore/milestones{/number}","notifications_url":"https://api.github.com/repos/Tapjoy/chore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tapjoy/chore/labels{/name}","releases_url":"https://api.github.com/repos/Tapjoy/chore/releases{/id}","deployments_url":"https://api.github.com/repos/Tapjoy/chore/deployments","created_at":"2014-09-26T19:27:36Z","updated_at":"2016-03-22T22:22:58Z","pushed_at":"2016-03-23T16:07:14Z","git_url":"git://github.com/Tapjoy/chore.git","ssh_url":"git@github.com:Tapjoy/chore.git","clone_url":"https://github.com/Tapjoy/chore.git","svn_url":"https://github.com/Tapjoy/chore","homepage":"","size":1024,"stargazers_count":16,"watchers_count":16,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":5,"forks":3,"open_issues":5,"watchers":16,"default_branch":"master"}},"base":{"label":"Tapjoy:master","ref":"master","sha":"6fd14ea56dec4f1939a55e7524ef80c1b7a05dbd","user":{"login":"Tapjoy","id":716849,"avatar_url":"https://avatars.githubusercontent.com/u/716849?v=3","gravatar_id":"","url":"https://api.github.com/users/Tapjoy","html_url":"https://github.com/Tapjoy","followers_url":"https://api.github.com/users/Tapjoy/followers","following_url":"https://api.github.com/users/Tapjoy/following{/other_user}","gists_url":"https://api.github.com/users/Tapjoy/gists{/gist_id}","starred_url":"https://api.github.com/users/Tapjoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tapjoy/subscriptions","organizations_url":"https://api.github.com/users/Tapjoy/orgs","repos_url":"https://api.github.com/users/Tapjoy/repos","events_url":"https://api.github.com/users/Tapjoy/events{/privacy}","received_events_url":"https://api.github.com/users/Tapjoy/received_events","type":"Organization","site_admin":false},"repo":{"id":24512598,"name":"chore","full_name":"Tapjoy/chore","owner":{"login":"Tapjoy","id":716849,"avatar_url":"https://avatars.githubusercontent.com/u/716849?v=3","gravatar_id":"","url":"https://api.github.com/users/Tapjoy","html_url":"https://github.com/Tapjoy","followers_url":"https://api.github.com/users/Tapjoy/followers","following_url":"https://api.github.com/users/Tapjoy/following{/other_user}","gists_url":"https://api.github.com/users/Tapjoy/gists{/gist_id}","starred_url":"https://api.github.com/users/Tapjoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tapjoy/subscriptions","organizations_url":"https://api.github.com/users/Tapjoy/orgs","repos_url":"https://api.github.com/users/Tapjoy/repos","events_url":"https://api.github.com/users/Tapjoy/events{/privacy}","received_events_url":"https://api.github.com/users/Tapjoy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tapjoy/chore","description":"Job processing...for the future!","fork":false,"url":"https://api.github.com/repos/Tapjoy/chore","forks_url":"https://api.github.com/repos/Tapjoy/chore/forks","keys_url":"https://api.github.com/repos/Tapjoy/chore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tapjoy/chore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tapjoy/chore/teams","hooks_url":"https://api.github.com/repos/Tapjoy/chore/hooks","issue_events_url":"https://api.github.com/repos/Tapjoy/chore/issues/events{/number}","events_url":"https://api.github.com/repos/Tapjoy/chore/events","assignees_url":"https://api.github.com/repos/Tapjoy/chore/assignees{/user}","branches_url":"https://api.github.com/repos/Tapjoy/chore/branches{/branch}","tags_url":"https://api.github.com/repos/Tapjoy/chore/tags","blobs_url":"https://api.github.com/repos/Tapjoy/chore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tapjoy/chore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tapjoy/chore/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tapjoy/chore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tapjoy/chore/statuses/{sha}","languages_url":"https://api.github.com/repos/Tapjoy/chore/languages","stargazers_url":"https://api.github.com/repos/Tapjoy/chore/stargazers","contributors_url":"https://api.github.com/repos/Tapjoy/chore/contributors","subscribers_url":"https://api.github.com/repos/Tapjoy/chore/subscribers","subscription_url":"https://api.github.com/repos/Tapjoy/chore/subscription","commits_url":"https://api.github.com/repos/Tapjoy/chore/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tapjoy/chore/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tapjoy/chore/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tapjoy/chore/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tapjoy/chore/contents/{+path}","compare_url":"https://api.github.com/repos/Tapjoy/chore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tapjoy/chore/merges","archive_url":"https://api.github.com/repos/Tapjoy/chore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tapjoy/chore/downloads","issues_url":"https://api.github.com/repos/Tapjoy/chore/issues{/number}","pulls_url":"https://api.github.com/repos/Tapjoy/chore/pulls{/number}","milestones_url":"https://api.github.com/repos/Tapjoy/chore/milestones{/number}","notifications_url":"https://api.github.com/repos/Tapjoy/chore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tapjoy/chore/labels{/name}","releases_url":"https://api.github.com/repos/Tapjoy/chore/releases{/id}","deployments_url":"https://api.github.com/repos/Tapjoy/chore/deployments","created_at":"2014-09-26T19:27:36Z","updated_at":"2016-03-22T22:22:58Z","pushed_at":"2016-03-23T16:07:14Z","git_url":"git://github.com/Tapjoy/chore.git","ssh_url":"git@github.com:Tapjoy/chore.git","clone_url":"https://github.com/Tapjoy/chore.git","svn_url":"https://github.com/Tapjoy/chore","homepage":"","size":1024,"stargazers_count":16,"watchers_count":16,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":5,"forks":3,"open_issues":5,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/30"},"html":{"href":"https://github.com/Tapjoy/chore/pull/30"},"issue":{"href":"https://api.github.com/repos/Tapjoy/chore/issues/30"},"comments":{"href":"https://api.github.com/repos/Tapjoy/chore/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Tapjoy/chore/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/Tapjoy/chore/statuses/51aa3c1b29c1a0d00b19bbe6109975fb43df4b00"}}}}