sidekiq-pauzer 2.2.0 → 3.0.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
  SHA256:
3
- metadata.gz: b7181876b443f54e7ce377358fc1dc9920bf6aff98973aa5d1499e1b2a56401a
4
- data.tar.gz: ee6a16525e36c8c4ba468817be43298cfd5905760e5fb737e6a743ec1577b0fc
3
+ metadata.gz: b7ad60f6b5eadbbf347139ad0eaef9962e1983f90cf84bf5d1b409bb19ddfc4d
4
+ data.tar.gz: 01ff41aac0537faad75897dfa15a2427f00ee6d3a04e9b40ac686d8a52b05770
5
5
  SHA512:
6
- metadata.gz: 27c52a1aa9e02ad2dbb48ea2be6af3458e11798974d963e03a0f7edb729d8fc6dd09ab56f259be8006da5bc9a1cf51e9e87cb8e7b35c6f2f9174d381d76d4d29
7
- data.tar.gz: fb4f9043119f8c26b1be9aa5d6aed8cdd14640a7a6b630607bb3694ec0e0f1ccad8e8e3a802a57949c70cafd45e0375bfed99138badd303daa217d1bdc4da97c
6
+ metadata.gz: bd6aa63500df79f60d3fe1c65fb05e51c6dda01f2e431fe5637d4431220a01bcdf5255626cb484dcc08d8077652fb7746c52c17e68ff0acf3e5898608707213f
7
+ data.tar.gz: 2197a6faf19fae846a04f5f75271af586041b751f6a06a49d6cf5cb9e351a5c496db502a6cdfc38490eb314a2b3d84becaf20550cea59d1828f1ad5c463a5da9
data/README.adoc CHANGED
@@ -96,16 +96,16 @@ dropped.
96
96
 
97
97
  This library aims to support and work with following Sidekiq versions:
98
98
 
99
- * Sidekiq 6.5.x
100
99
  * Sidekiq 7.0.x
101
100
  * Sidekiq 7.1.x
102
101
 
103
102
 
104
103
  == Development
105
104
 
106
- scripts/update-gemfiles
107
- scripts/run-rspec
108
- bundle exec rubocop
105
+ bundle install
106
+ bundle exec appraisal generate
107
+ bundle exec appraisal install
108
+ bundle exec rake
109
109
 
110
110
 
111
111
  == Contributing
@@ -3,45 +3,23 @@
3
3
  require "sidekiq"
4
4
  require "sidekiq/fetch"
5
5
 
6
- require_relative "./runtime"
7
-
8
6
  module Sidekiq
9
7
  module Pauzer
10
8
  # Default Sidekiq's BasicFetch infused with Pauzer
11
9
  class BasicFetch < Sidekiq::BasicFetch
12
10
  private
13
11
 
14
- if Runtime::SIDEKIQ_SEVEN
15
- def queues_cmd
16
- queues =
17
- if @strictly_ordered_queues
18
- @queues
19
- else
20
- permute = @queues.dup
21
- permute.shuffle!
22
- permute.uniq!
23
- permute
24
- end
25
-
26
- excluding_paused(queues)
27
- end
28
- else
29
- def queues_cmd
30
- queues =
31
- if @strictly_ordered_queues
32
- @queues[0...-1]
33
- else
34
- permute = @queues.dup
35
- permute.shuffle!
36
- permute.uniq!
37
- permute
38
- end
39
-
40
- excluding_paused(queues) << { timeout: Sidekiq::BasicFetch::TIMEOUT }
41
- end
42
- end
12
+ def queues_cmd
13
+ queues =
14
+ if @strictly_ordered_queues
15
+ @queues
16
+ else
17
+ permute = @queues.dup
18
+ permute.shuffle!
19
+ permute.uniq!
20
+ permute
21
+ end
43
22
 
44
- def excluding_paused(queues)
45
23
  queues - Pauzer.paused_queues.map { |name| "queue:#{name}" }
46
24
  end
47
25
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  require "concurrent"
4
4
 
5
- require_relative "./adapters"
6
-
7
5
  module Sidekiq
8
6
  module Pauzer
9
7
  # @api internal
@@ -14,7 +12,8 @@ module Sidekiq
14
12
 
15
13
  # @param config [Config]
16
14
  def initialize(config)
17
- @names = Concurrent::Array.new
15
+ @mutex = Mutex.new
16
+ @names = []
18
17
  @redis_key = config.redis_key
19
18
  @refresher = initialize_refresher(config.refresh_rate)
20
19
  end
@@ -22,21 +21,21 @@ module Sidekiq
22
21
  def each(&block)
23
22
  return to_enum __method__ unless block
24
23
 
25
- @names.dup.each(&block)
24
+ @mutex.synchronize { @names.dup }.each(&block)
26
25
 
27
26
  self
28
27
  end
29
28
 
30
29
  # @param name [#to_s]
31
30
  def pause!(name)
32
- Sidekiq.redis { |conn| Adapters[conn].add(conn, @redis_key, name.to_s) }
31
+ Sidekiq.redis { |conn| conn.call("SADD", @redis_key, name.to_s) }
33
32
 
34
33
  refresh
35
34
  end
36
35
 
37
36
  # @param name [#to_s]
38
37
  def unpause!(name)
39
- Sidekiq.redis { |conn| Adapters[conn].remove(conn, @redis_key, name.to_s) }
38
+ Sidekiq.redis { |conn| conn.call("SREM", @redis_key, name.to_s) }
40
39
 
41
40
  refresh
42
41
  end
@@ -72,7 +71,16 @@ module Sidekiq
72
71
  end
73
72
 
74
73
  def refresh
75
- @names.replace(Sidekiq.redis { |conn| Adapters[conn].list(conn, @redis_key) })
74
+ @mutex.synchronize do
75
+ names = Sidekiq.redis do |conn|
76
+ # Cursor is not atomic, so there may be duplicates because of
77
+ # concurrent update operations
78
+ # See: https://redis.io/commands/scan/#scan-guarantees
79
+ conn.sscan(@redis_key).to_a.uniq.each(&:freeze)
80
+ end
81
+
82
+ @names.replace(names)
83
+ end
76
84
 
77
85
  self
78
86
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "2.2.0"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
@@ -85,9 +85,6 @@ module Sidekiq
85
85
  @queues.to_a
86
86
  end
87
87
 
88
- # @deprecated Use {.paused_queues}
89
- alias paused_queue_names paused_queues
90
-
91
88
  # Yields `config` for a block.
92
89
  #
93
90
  # @example
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-pauzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2023-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.5'
33
+ version: '7.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '6.5'
40
+ version: '7.0'
41
41
  description:
42
42
  email:
43
43
  - alexey@zapparov.com
@@ -48,16 +48,12 @@ files:
48
48
  - README.adoc
49
49
  - lib/sidekiq-pauzer.rb
50
50
  - lib/sidekiq/pauzer.rb
51
- - lib/sidekiq/pauzer/adapters.rb
52
- - lib/sidekiq/pauzer/adapters/redis.rb
53
- - lib/sidekiq/pauzer/adapters/redis_client.rb
54
51
  - lib/sidekiq/pauzer/basic_fetch.rb
55
52
  - lib/sidekiq/pauzer/config.rb
56
53
  - lib/sidekiq/pauzer/patches/queue.rb
57
54
  - lib/sidekiq/pauzer/patches/web_action.rb
58
55
  - lib/sidekiq/pauzer/patches/web_application.rb
59
56
  - lib/sidekiq/pauzer/queues.rb
60
- - lib/sidekiq/pauzer/runtime.rb
61
57
  - lib/sidekiq/pauzer/version.rb
62
58
  - lib/sidekiq/pauzer/web.rb
63
59
  - web/views/queues.erb
@@ -66,9 +62,9 @@ licenses:
66
62
  - MIT
67
63
  metadata:
68
64
  homepage_uri: https://gitlab.com/ixti/sidekiq-pauzer
69
- source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v2.2.0
65
+ source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v3.0.0
70
66
  bug_tracker_uri: https://gitlab.com/ixti/sidekiq-pauzer/issues
71
- changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v2.2.0/CHANGES.md
67
+ changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v3.0.0/CHANGES.md
72
68
  rubygems_mfa_required: 'true'
73
69
  post_install_message:
74
70
  rdoc_options: []
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sidekiq
4
- module Pauzer
5
- module Adapters
6
- # redis-rb adapter
7
- module Redis
8
- class << self
9
- def adapts?(redis)
10
- return true if defined?(::Redis) && redis.is_a?(::Redis)
11
- return true if defined?(::Redis::Namespace) && redis.is_a?(::Redis::Namespace)
12
-
13
- false
14
- end
15
-
16
- def add(redis, key, queue)
17
- redis.sadd(key, queue)
18
- end
19
-
20
- def remove(redis, key, queue)
21
- redis.srem(key, queue)
22
- end
23
-
24
- def list(redis, key)
25
- # Cursor is not atomic, so there may be duplicates because of
26
- # concurrent update operations
27
- # See: https://redis.io/commands/scan/#scan-guarantees
28
- redis.sscan_each(key).to_a.uniq.each(&:freeze)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../runtime"
4
-
5
- module Sidekiq
6
- module Pauzer
7
- module Adapters
8
- # redis-client adapter
9
- module RedisClient
10
- class << self
11
- def adapts?(redis)
12
- return true if Runtime::SIDEKIQ_SEVEN
13
- return true if defined?(::RedisClient) && redis.is_a?(::RedisClient)
14
- return true if defined?(::RedisClient::Decorator::Client) && redis.is_a?(::RedisClient::Decorator::Client)
15
-
16
- false
17
- end
18
-
19
- def add(redis, key, queue)
20
- redis.call("SADD", key, queue)
21
- end
22
-
23
- def remove(redis, key, queue)
24
- redis.call("SREM", key, queue)
25
- end
26
-
27
- def list(redis, key)
28
- # Cursor is not atomic, so there may be duplicates because of
29
- # concurrent update operations
30
- # See: https://redis.io/commands/scan/#scan-guarantees
31
- redis.sscan(key).to_a.uniq.each(&:freeze)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "./adapters/redis"
4
- require_relative "./adapters/redis_client"
5
-
6
- module Sidekiq
7
- module Pauzer
8
- # @api internal
9
- module Adapters
10
- def self.[](redis)
11
- return Adapters::RedisClient if Adapters::RedisClient.adapts?(redis)
12
- return Adapters::Redis if Adapters::Redis.adapts?(redis)
13
-
14
- raise TypeError, "Unsupported redis client: #{redis.class}"
15
- end
16
- end
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq"
4
-
5
- module Sidekiq
6
- module Pauzer
7
- module Runtime
8
- SIDEKIQ_SEVEN = Gem::Version.new("7.0.0") <= Gem::Version.new(Sidekiq::VERSION)
9
- end
10
- end
11
- end