{"action":"created","comment":{"url":"https://api.github.com/repos/phstc/shoryuken/pulls/comments/44206870","id":44206870,"diff_hunk":"@@ -57,11 +45,24 @@ def fetch(queue, available_processors)\n           @manager.async.dispatch\n         end\n       end\n-\n     end\n \n     private\n \n+    def receive_messages(queue, limit)","path":"lib/shoryuken/fetcher.rb","position":57,"original_position":57,"commit_id":"ff36e5bed6fd668484127dde303856d2603fa7a2","original_commit_id":"ff36e5bed6fd668484127dde303856d2603fa7a2","user":{"login":"gshutler","id":81344,"avatar_url":"https://avatars.githubusercontent.com/u/81344?v=3","gravatar_id":"","url":"https://api.github.com/users/gshutler","html_url":"https://github.com/gshutler","followers_url":"https://api.github.com/users/gshutler/followers","following_url":"https://api.github.com/users/gshutler/following{/other_user}","gists_url":"https://api.github.com/users/gshutler/gists{/gist_id}","starred_url":"https://api.github.com/users/gshutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gshutler/subscriptions","organizations_url":"https://api.github.com/users/gshutler/orgs","repos_url":"https://api.github.com/users/gshutler/repos","events_url":"https://api.github.com/users/gshutler/events{/privacy}","received_events_url":"https://api.github.com/users/gshutler/received_events","type":"User","site_admin":false},"body":"Because it can be without breaking the implementation, reducing the surface area of the class.","created_at":"2015-11-07T02:59:26Z","updated_at":"2015-11-07T02:59:26Z","html_url":"https://github.com/phstc/shoryuken/pull/106#discussion_r44206870","pull_request_url":"https://api.github.com/repos/phstc/shoryuken/pulls/106","_links":{"self":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/comments/44206870"},"html":{"href":"https://github.com/phstc/shoryuken/pull/106#discussion_r44206870"},"pull_request":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/106"}}},"pull_request":{"url":"https://api.github.com/repos/phstc/shoryuken/pulls/106","id":37039759,"html_url":"https://github.com/phstc/shoryuken/pull/106","diff_url":"https://github.com/phstc/shoryuken/pull/106.diff","patch_url":"https://github.com/phstc/shoryuken/pull/106.patch","issue_url":"https://api.github.com/repos/phstc/shoryuken/issues/106","number":106,"state":"open","locked":false,"title":"Extracted queue polling strategy","user":{"login":"gshutler","id":81344,"avatar_url":"https://avatars.githubusercontent.com/u/81344?v=3","gravatar_id":"","url":"https://api.github.com/users/gshutler","html_url":"https://github.com/gshutler","followers_url":"https://api.github.com/users/gshutler/followers","following_url":"https://api.github.com/users/gshutler/following{/other_user}","gists_url":"https://api.github.com/users/gshutler/gists{/gist_id}","starred_url":"https://api.github.com/users/gshutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gshutler/subscriptions","organizations_url":"https://api.github.com/users/gshutler/orgs","repos_url":"https://api.github.com/users/gshutler/repos","events_url":"https://api.github.com/users/gshutler/events{/privacy}","received_events_url":"https://api.github.com/users/gshutler/received_events","type":"User","site_admin":false},"body":"In order to be able to customize the order and manner in which Shoryuken polls SQS queues, the previous hard-coded strategy was extracted into a separate class.\r\n\r\nThis meant that some of the method names were altered to be more generic (for example rebalance_queue_weight! became messages_received), otherwise this was a direct extraction.\r\n\r\n---\r\n\r\nI don't think this is 100% ready for merging, I'm not entirely happy with the names and so forth but I think it's solid enough to start having a discussion around.\r\n\r\nMy motivation was to be able to have more strict prioritization semantics than provided by the default implementation. I also wanted the option to do an extended poll on the highest priority queue if all queues are empty rather than either continually polling them all or sleeping to not poll anything.\r\n\r\nThis is my custom strategy that achieves that:\r\n\r\n```ruby\r\nclass StrictPriorityPolling\r\n  include Shoryuken::Util\r\n\r\n  def initialize(queues)\r\n    @active_queues = unparse_queues(queues)\r\n    @prioritized_queues = @active_queues.sort_by { |queue, priority| -priority }.map(&:first)\r\n    @highest_priority = @prioritized_queues.first\r\n    @queues_since_messages = 0\r\n  end\r\n\r\n  def active_queues\r\n    @active_queues\r\n  end\r\n\r\n  def next_queue\r\n    options = {}\r\n\r\n    queue = @prioritized_queues[@queues_since_messages % @prioritized_queues.length]\r\n\r\n    if @highest_priority == queue && @queues_since_messages > 0\r\n      options[:wait_time_seconds] = 2\r\n    end\r\n\r\n    @queues_since_messages += 1\r\n\r\n    Shoryuken::Polling::QueueConfiguration.new(queue, options)\r\n  end\r\n\r\n  def messages_present(queue)\r\n    @queues_since_messages = 0\r\n  end\r\n\r\n  def pause(queue)\r\n    # No-op\r\n  end\r\n\r\n  def restart(queue)\r\n    # No-op\r\n  end\r\nend\r\n\r\nShoryuken.configure_server do |config|\r\n  config.options[:polling_strategy] = StrictPriorityPolling\r\nend\r\n```\r\n\r\nFrom this, a strategy could be developed that may satisfy #92.\r\n","created_at":"2015-06-05T15:03:47Z","updated_at":"2015-11-07T02:59:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b7f87b99f604232b6d087ca9ef835c2c597b3ba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phstc/shoryuken/pulls/106/commits","review_comments_url":"https://api.github.com/repos/phstc/shoryuken/pulls/106/comments","review_comment_url":"https://api.github.com/repos/phstc/shoryuken/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phstc/shoryuken/issues/106/comments","statuses_url":"https://api.github.com/repos/phstc/shoryuken/statuses/ff36e5bed6fd668484127dde303856d2603fa7a2","head":{"label":"gshutler:queue-strategy","ref":"queue-strategy","sha":"ff36e5bed6fd668484127dde303856d2603fa7a2","user":{"login":"gshutler","id":81344,"avatar_url":"https://avatars.githubusercontent.com/u/81344?v=3","gravatar_id":"","url":"https://api.github.com/users/gshutler","html_url":"https://github.com/gshutler","followers_url":"https://api.github.com/users/gshutler/followers","following_url":"https://api.github.com/users/gshutler/following{/other_user}","gists_url":"https://api.github.com/users/gshutler/gists{/gist_id}","starred_url":"https://api.github.com/users/gshutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gshutler/subscriptions","organizations_url":"https://api.github.com/users/gshutler/orgs","repos_url":"https://api.github.com/users/gshutler/repos","events_url":"https://api.github.com/users/gshutler/events{/privacy}","received_events_url":"https://api.github.com/users/gshutler/received_events","type":"User","site_admin":false},"repo":{"id":36860613,"name":"shoryuken","full_name":"gshutler/shoryuken","owner":{"login":"gshutler","id":81344,"avatar_url":"https://avatars.githubusercontent.com/u/81344?v=3","gravatar_id":"","url":"https://api.github.com/users/gshutler","html_url":"https://github.com/gshutler","followers_url":"https://api.github.com/users/gshutler/followers","following_url":"https://api.github.com/users/gshutler/following{/other_user}","gists_url":"https://api.github.com/users/gshutler/gists{/gist_id}","starred_url":"https://api.github.com/users/gshutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gshutler/subscriptions","organizations_url":"https://api.github.com/users/gshutler/orgs","repos_url":"https://api.github.com/users/gshutler/repos","events_url":"https://api.github.com/users/gshutler/events{/privacy}","received_events_url":"https://api.github.com/users/gshutler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gshutler/shoryuken","description":"A super efficient AWS SQS thread based message processor for Ruby","fork":true,"url":"https://api.github.com/repos/gshutler/shoryuken","forks_url":"https://api.github.com/repos/gshutler/shoryuken/forks","keys_url":"https://api.github.com/repos/gshutler/shoryuken/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gshutler/shoryuken/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gshutler/shoryuken/teams","hooks_url":"https://api.github.com/repos/gshutler/shoryuken/hooks","issue_events_url":"https://api.github.com/repos/gshutler/shoryuken/issues/events{/number}","events_url":"https://api.github.com/repos/gshutler/shoryuken/events","assignees_url":"https://api.github.com/repos/gshutler/shoryuken/assignees{/user}","branches_url":"https://api.github.com/repos/gshutler/shoryuken/branches{/branch}","tags_url":"https://api.github.com/repos/gshutler/shoryuken/tags","blobs_url":"https://api.github.com/repos/gshutler/shoryuken/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gshutler/shoryuken/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gshutler/shoryuken/git/refs{/sha}","trees_url":"https://api.github.com/repos/gshutler/shoryuken/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gshutler/shoryuken/statuses/{sha}","languages_url":"https://api.github.com/repos/gshutler/shoryuken/languages","stargazers_url":"https://api.github.com/repos/gshutler/shoryuken/stargazers","contributors_url":"https://api.github.com/repos/gshutler/shoryuken/contributors","subscribers_url":"https://api.github.com/repos/gshutler/shoryuken/subscribers","subscription_url":"https://api.github.com/repos/gshutler/shoryuken/subscription","commits_url":"https://api.github.com/repos/gshutler/shoryuken/commits{/sha}","git_commits_url":"https://api.github.com/repos/gshutler/shoryuken/git/commits{/sha}","comments_url":"https://api.github.com/repos/gshutler/shoryuken/comments{/number}","issue_comment_url":"https://api.github.com/repos/gshutler/shoryuken/issues/comments{/number}","contents_url":"https://api.github.com/repos/gshutler/shoryuken/contents/{+path}","compare_url":"https://api.github.com/repos/gshutler/shoryuken/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gshutler/shoryuken/merges","archive_url":"https://api.github.com/repos/gshutler/shoryuken/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gshutler/shoryuken/downloads","issues_url":"https://api.github.com/repos/gshutler/shoryuken/issues{/number}","pulls_url":"https://api.github.com/repos/gshutler/shoryuken/pulls{/number}","milestones_url":"https://api.github.com/repos/gshutler/shoryuken/milestones{/number}","notifications_url":"https://api.github.com/repos/gshutler/shoryuken/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gshutler/shoryuken/labels{/name}","releases_url":"https://api.github.com/repos/gshutler/shoryuken/releases{/id}","created_at":"2015-06-04T09:20:22Z","updated_at":"2015-06-04T09:20:22Z","pushed_at":"2015-06-24T11:19:50Z","git_url":"git://github.com/gshutler/shoryuken.git","ssh_url":"git@github.com:gshutler/shoryuken.git","clone_url":"https://github.com/gshutler/shoryuken.git","svn_url":"https://github.com/gshutler/shoryuken","homepage":"","size":456,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"phstc:master","ref":"master","sha":"290b1cb4c4c40f34881d7f7b7a3beda949099cf5","user":{"login":"phstc","id":105652,"avatar_url":"https://avatars.githubusercontent.com/u/105652?v=3","gravatar_id":"","url":"https://api.github.com/users/phstc","html_url":"https://github.com/phstc","followers_url":"https://api.github.com/users/phstc/followers","following_url":"https://api.github.com/users/phstc/following{/other_user}","gists_url":"https://api.github.com/users/phstc/gists{/gist_id}","starred_url":"https://api.github.com/users/phstc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phstc/subscriptions","organizations_url":"https://api.github.com/users/phstc/orgs","repos_url":"https://api.github.com/users/phstc/repos","events_url":"https://api.github.com/users/phstc/events{/privacy}","received_events_url":"https://api.github.com/users/phstc/received_events","type":"User","site_admin":false},"repo":{"id":23578850,"name":"shoryuken","full_name":"phstc/shoryuken","owner":{"login":"phstc","id":105652,"avatar_url":"https://avatars.githubusercontent.com/u/105652?v=3","gravatar_id":"","url":"https://api.github.com/users/phstc","html_url":"https://github.com/phstc","followers_url":"https://api.github.com/users/phstc/followers","following_url":"https://api.github.com/users/phstc/following{/other_user}","gists_url":"https://api.github.com/users/phstc/gists{/gist_id}","starred_url":"https://api.github.com/users/phstc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phstc/subscriptions","organizations_url":"https://api.github.com/users/phstc/orgs","repos_url":"https://api.github.com/users/phstc/repos","events_url":"https://api.github.com/users/phstc/events{/privacy}","received_events_url":"https://api.github.com/users/phstc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phstc/shoryuken","description":"A super efficient AWS SQS thread based message processor for Ruby","fork":false,"url":"https://api.github.com/repos/phstc/shoryuken","forks_url":"https://api.github.com/repos/phstc/shoryuken/forks","keys_url":"https://api.github.com/repos/phstc/shoryuken/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phstc/shoryuken/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phstc/shoryuken/teams","hooks_url":"https://api.github.com/repos/phstc/shoryuken/hooks","issue_events_url":"https://api.github.com/repos/phstc/shoryuken/issues/events{/number}","events_url":"https://api.github.com/repos/phstc/shoryuken/events","assignees_url":"https://api.github.com/repos/phstc/shoryuken/assignees{/user}","branches_url":"https://api.github.com/repos/phstc/shoryuken/branches{/branch}","tags_url":"https://api.github.com/repos/phstc/shoryuken/tags","blobs_url":"https://api.github.com/repos/phstc/shoryuken/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phstc/shoryuken/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phstc/shoryuken/git/refs{/sha}","trees_url":"https://api.github.com/repos/phstc/shoryuken/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phstc/shoryuken/statuses/{sha}","languages_url":"https://api.github.com/repos/phstc/shoryuken/languages","stargazers_url":"https://api.github.com/repos/phstc/shoryuken/stargazers","contributors_url":"https://api.github.com/repos/phstc/shoryuken/contributors","subscribers_url":"https://api.github.com/repos/phstc/shoryuken/subscribers","subscription_url":"https://api.github.com/repos/phstc/shoryuken/subscription","commits_url":"https://api.github.com/repos/phstc/shoryuken/commits{/sha}","git_commits_url":"https://api.github.com/repos/phstc/shoryuken/git/commits{/sha}","comments_url":"https://api.github.com/repos/phstc/shoryuken/comments{/number}","issue_comment_url":"https://api.github.com/repos/phstc/shoryuken/issues/comments{/number}","contents_url":"https://api.github.com/repos/phstc/shoryuken/contents/{+path}","compare_url":"https://api.github.com/repos/phstc/shoryuken/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phstc/shoryuken/merges","archive_url":"https://api.github.com/repos/phstc/shoryuken/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phstc/shoryuken/downloads","issues_url":"https://api.github.com/repos/phstc/shoryuken/issues{/number}","pulls_url":"https://api.github.com/repos/phstc/shoryuken/pulls{/number}","milestones_url":"https://api.github.com/repos/phstc/shoryuken/milestones{/number}","notifications_url":"https://api.github.com/repos/phstc/shoryuken/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phstc/shoryuken/labels{/name}","releases_url":"https://api.github.com/repos/phstc/shoryuken/releases{/id}","created_at":"2014-09-02T13:04:10Z","updated_at":"2015-11-05T15:05:54Z","pushed_at":"2015-11-06T23:24:34Z","git_url":"git://github.com/phstc/shoryuken.git","ssh_url":"git@github.com:phstc/shoryuken.git","clone_url":"https://github.com/phstc/shoryuken.git","svn_url":"https://github.com/phstc/shoryuken","homepage":"","size":1851,"stargazers_count":533,"watchers_count":533,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":14,"forks":57,"open_issues":14,"watchers":533,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/106"},"html":{"href":"https://github.com/phstc/shoryuken/pull/106"},"issue":{"href":"https://api.github.com/repos/phstc/shoryuken/issues/106"},"comments":{"href":"https://api.github.com/repos/phstc/shoryuken/issues/106/comments"},"review_comments":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/106/comments"},"review_comment":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phstc/shoryuken/pulls/106/commits"},"statuses":{"href":"https://api.github.com/repos/phstc/shoryuken/statuses/ff36e5bed6fd668484127dde303856d2603fa7a2"}}}}