sidekiq-throttled 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11fca504d3cc0e0c497b31f28eeff11ddea99646
4
- data.tar.gz: 57f37328ff6fea478e675531cf8cc31404e9fea1
3
+ metadata.gz: 427e3b20c7b521948d64ca4d6845c660eaebf278
4
+ data.tar.gz: 25ccc08885012c0f7269651399d117d1bca07c9c
5
5
  SHA512:
6
- metadata.gz: 113114f75677f217ac29c68a08b23b7942cebfcb2692e7e231fa3b759eb5eb282ea75ce589623c354d8366e651d57d7c86a0a152d5f8db57305ae7ccd9776970
7
- data.tar.gz: 120307bb6c3cf8dc22aa68a1b56048460c3b3d160c34a439aefce9f0b576536616ba19ce9ff7084c52e62154607e37e7c3d04933d4463e07b852d2911f60cd85
6
+ metadata.gz: a8d5aa36914a6c4a69f6b644defd5c97a34ca38d04c59707b4b74a58d559911509599e51428670d875c1b4a8aef10e8d944be51cdaafbb9b0196cab7ac9b9250
7
+ data.tar.gz: 06af7fc7818f88df36c017e92c1033429ad782ab3a0c11eb698b531d649efb7cbb294f1e1865bbaa8eb33de4c023a393f6429edca75d4806f4c501ade2a37b21
data/.travis.yml CHANGED
@@ -20,7 +20,6 @@ matrix:
20
20
  - rvm: rbx-2
21
21
  fast_finish: true
22
22
  gemfile:
23
- - gemfiles/sidekiq_3.x.gemfile
24
23
  - gemfiles/sidekiq_4.0.gemfile
25
24
  - gemfiles/sidekiq_4.1.gemfile
26
25
  - gemfiles/sidekiq_latest.gemfile
data/Appraisals CHANGED
@@ -1,8 +1,3 @@
1
- appraise "sidekiq-3.x" do
2
- gem "celluloid"
3
- gem "sidekiq", "~> 3.0"
4
- end
5
-
6
1
  appraise "sidekiq-4.0" do
7
2
  gem "sidekiq", "~> 4.0.0"
8
3
  end
data/CHANGES.md CHANGED
@@ -1,8 +1,7 @@
1
- ## 0.4.1 (2016-08-18)
1
+ ## 0.5.0 (2016-08-18)
2
2
 
3
- * [#15](https://github.com/sensortower/sidekiq-throttled/pull/15)
4
- Fix throttled web UI on older versions of sidekiq.
5
- ([@palanglung])
3
+ * Drop Sidekiq 3.x support.
4
+ ([@ixti])
6
5
 
7
6
 
8
7
  ## 0.4.0 (2016-05-17)
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Sidekiq::Throttled
2
2
 
3
- [![Gem Version](https://img.shields.io/badge/gem%20version-0.4.x-brightgreen.svg)](http://rubygems.org/gems/sidekiq-throttled)
4
- [![Build Status](https://travis-ci.org/sensortower/sidekiq-throttled.svg?branch=v0.4.x)](https://travis-ci.org/sensortower/sidekiq-throttled)
5
- [![Code Climate](https://codeclimate.com/github/sensortower/sidekiq-throttled.svg?branch=v0.4.x)](https://codeclimate.com/github/sensortower/sidekiq-throttled)
6
- [![Coverage Status](https://coveralls.io/repos/github/sensortower/sidekiq-throttled/badge.svg?branch=v0.4.x)](https://coveralls.io/github/sensortower/sidekiq-throttled?branch=v0.4.x)
3
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-throttled.svg)](http://rubygems.org/gems/sidekiq-throttled)
4
+ [![Build Status](https://travis-ci.org/sensortower/sidekiq-throttled.svg?branch=master)](https://travis-ci.org/sensortower/sidekiq-throttled)
5
+ [![Code Climate](https://codeclimate.com/github/sensortower/sidekiq-throttled.svg?branch=master)](https://codeclimate.com/github/sensortower/sidekiq-throttled)
6
+ [![Coverage Status](https://coveralls.io/repos/sensortower/sidekiq-throttled/badge.svg?branch=master&service=github)](https://coveralls.io/github/sensortower/sidekiq-throttled?branch=master)
7
7
 
8
- Concurrency and threshold throttling for [Sidekiq](https://github.com/mperham/sidekiq/).
8
+ Concurrency and threshold throttling for [Sidekiq][sidekiq].
9
9
 
10
10
 
11
11
  ## Installation
@@ -126,7 +126,13 @@ versions:
126
126
  * Ruby 2.2.x
127
127
  * Ruby 2.3.x
128
128
 
129
- [travis]: http://travis-ci.org/sensortower/sidekiq-throttled
129
+
130
+ ## Supported Sidekiq Versions
131
+
132
+ This library aims to support work with following [Sidekiq][sidekiq] versions:
133
+
134
+ * Sidekiq 4.0.x
135
+ * Sidekiq 4.1.x
130
136
 
131
137
 
132
138
  ## Contributing
@@ -143,3 +149,7 @@ versions:
143
149
 
144
150
  Copyright (c) 2015 SensorTower Inc.
145
151
  See LICENSE.md for further details.
152
+
153
+
154
+ [travis]: http://travis-ci.org/sensortower/sidekiq-throttled
155
+ [sidekiq]: https://github.com/mperham/sidekiq
@@ -42,8 +42,8 @@ module Sidekiq
42
42
  # @return [void]
43
43
  def setup!
44
44
  Sidekiq.configure_server do |config|
45
- require "sidekiq/throttled/basic_fetch"
46
- Sidekiq.options[:fetch] = Sidekiq::Throttled::BasicFetch
45
+ require "sidekiq/throttled/fetch"
46
+ Sidekiq.options[:fetch] = Sidekiq::Throttled::Fetch
47
47
 
48
48
  require "sidekiq/throttled/middleware"
49
49
  config.server_middleware do |chain|
@@ -1,26 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "celluloid" if Sidekiq::VERSION < "4.0.0"
4
3
  require "sidekiq"
5
- require "sidekiq/fetch"
4
+ require "sidekiq/throttled/unit_of_work"
6
5
 
7
6
  module Sidekiq
8
7
  module Throttled
9
- # Throttled version of `Sidekiq::BasicFetch` fetcher strategy.
10
- class BasicFetch < ::Sidekiq::BasicFetch
8
+ # Throttled fetch strategy.
9
+ class Fetch
11
10
  TIMEOUT = 2
12
-
13
- class UnitOfWork < ::Sidekiq::BasicFetch::UnitOfWork
14
- alias job message if Sidekiq::VERSION < "4.0.0"
15
- end
11
+ private_constant :TIMEOUT
16
12
 
17
13
  def initialize(options)
18
- @strictly_ordered_queues = (options[:strict] ? true : false)
14
+ @strictly_ordered_queues = options[:strict]
19
15
  @queues = options[:queues].map { |q| "queue:#{q}" }
20
16
  @queues.uniq! if @strictly_ordered_queues
21
17
  end
22
18
 
23
- # @return [Sidekiq::BasicFetch::UnitOfWork, nil]
19
+ # @return [Sidekiq::Throttled::UnitOfWork, nil]
24
20
  def retrieve_work
25
21
  work = brpop
26
22
  return unless work
@@ -28,9 +24,9 @@ module Sidekiq
28
24
  work = UnitOfWork.new(*work)
29
25
  return work unless Throttled.throttled? work.job
30
26
 
31
- queue = "queue:#{work.queue_name}"
32
-
33
- Sidekiq.redis { |conn| conn.lpush(queue, work.job) }
27
+ Sidekiq.redis do |conn|
28
+ conn.lpush("queue:#{work.queue_name}", work.job)
29
+ end
34
30
 
35
31
  nil
36
32
  end
@@ -40,9 +36,12 @@ module Sidekiq
40
36
  # Tries to pop pair of `queue` and job `message` out of sidekiq queue.
41
37
  # @return [Array<String, String>, nil]
42
38
  def brpop
43
- queues = (@strictly_ordered_queues ? @queues : @queues.shuffle.uniq)
44
39
  Sidekiq.redis { |conn| conn.brpop(*queues, TIMEOUT) }
45
40
  end
41
+
42
+ def queues
43
+ (@strictly_ordered_queues ? @queues : @queues.shuffle.uniq)
44
+ end
46
45
  end
47
46
  end
48
47
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+
5
+ module Sidekiq
6
+ module Throttled
7
+ class UnitOfWork
8
+ QUEUE_NAME_PREFIX_RE = /^.*queue:/
9
+ private_constant :QUEUE_NAME_PREFIX_RE
10
+
11
+ attr_reader :queue
12
+
13
+ attr_reader :job
14
+
15
+ def initialize(queue, job)
16
+ @queue = queue
17
+ @job = job
18
+ end
19
+
20
+ def acknowledge
21
+ # do nothing
22
+ end
23
+
24
+ def queue_name
25
+ queue.sub(QUEUE_NAME_PREFIX_RE, "")
26
+ end
27
+
28
+ def requeue
29
+ Sidekiq.redis { |conn| conn.rpush("queue:#{queue_name}", job) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "0.4.1".freeze
6
+ VERSION = "0.5.0".freeze
7
7
  end
8
8
  end
@@ -27,7 +27,7 @@
27
27
  </td>
28
28
  <td style="vertical-align:middle;text-align:center;">
29
29
  <form action="<%= root_path %>throttled/<%= name %>" method="POST">
30
- <%= csrf_tag if respond_to?(:csrf_tag) %>
30
+ <%= csrf_tag %>
31
31
  <input type="hidden" name="_method" value="delete" />
32
32
  <button class="btn btn-danger" type="submit">Reset</button>
33
33
  </form>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-throttled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey V Zapparov
@@ -56,13 +56,12 @@ files:
56
56
  - LICENSE.md
57
57
  - README.md
58
58
  - Rakefile
59
- - gemfiles/sidekiq_3.x.gemfile
60
59
  - gemfiles/sidekiq_4.0.gemfile
61
60
  - gemfiles/sidekiq_4.1.gemfile
62
61
  - gemfiles/sidekiq_latest.gemfile
63
62
  - lib/sidekiq/throttled.rb
64
- - lib/sidekiq/throttled/basic_fetch.rb
65
63
  - lib/sidekiq/throttled/errors.rb
64
+ - lib/sidekiq/throttled/fetch.rb
66
65
  - lib/sidekiq/throttled/middleware.rb
67
66
  - lib/sidekiq/throttled/registry.rb
68
67
  - lib/sidekiq/throttled/strategy.rb
@@ -72,6 +71,7 @@ files:
72
71
  - lib/sidekiq/throttled/strategy/threshold.lua
73
72
  - lib/sidekiq/throttled/strategy/threshold.rb
74
73
  - lib/sidekiq/throttled/testing.rb
74
+ - lib/sidekiq/throttled/unit_of_work.rb
75
75
  - lib/sidekiq/throttled/version.rb
76
76
  - lib/sidekiq/throttled/web.rb
77
77
  - lib/sidekiq/throttled/web/index.html.erb
@@ -1,20 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "rubocop"
9
- gem "celluloid"
10
- gem "sidekiq", "~> 3.0"
11
-
12
- group :test do
13
- gem "coveralls"
14
- gem "rack-test"
15
- gem "simplecov", ">= 0.9"
16
- gem "sinatra", "~> 1.4", ">= 1.4.6"
17
- gem "timecop"
18
- end
19
-
20
- gemspec :path => "../"