sidekiq-pauzer 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq/pauzer/queues.rb +26 -65
- data/lib/sidekiq/pauzer/repository.rb +52 -0
- data/lib/sidekiq/pauzer/version.rb +1 -1
- data/lib/sidekiq/pauzer.rb +27 -27
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f31ae5cfdfd5dd4e693e42c0bb82fbef4012cf9289772542f32131d996ecf7
|
4
|
+
data.tar.gz: 9bf1d72ce135955e7887b0926df8b83e6e3333e2c86f7ba1f7070c1277a4c6fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7d00653876ac75e9cf299ad49152d8818380de5c18e670f023dfa5ffa07c9dd2b2755a8cfab71a9cb37e7b7d46d4e119653b314425ef8ffb57c1ffaa87414c
|
7
|
+
data.tar.gz: 89ab9cc7e4b0b90b4e3fa1b54b6a8e50577f52738faf0b96030edadc5fdddc1f6fd170b49aaf32be88a3538c31136404ee31576bf258ed2c7896584b189061cc
|
@@ -6,93 +6,54 @@ require "concurrent"
|
|
6
6
|
module Sidekiq
|
7
7
|
module Pauzer
|
8
8
|
# @api internal
|
9
|
+
# Eventually consistent list of paused queues. Used by Sidekiq fetchers to
|
10
|
+
# avoid hitting Redis on every fetch call.
|
9
11
|
class Queues
|
10
|
-
extend Forwardable
|
11
12
|
include Enumerable
|
12
13
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@names = [].freeze
|
21
|
-
@names_mutex = Mutex.new
|
22
|
-
@refresher = nil
|
23
|
-
@refresher_mutex = Mutex.new
|
14
|
+
# @param refresh_rate [Float]
|
15
|
+
# @param repository [Repository]
|
16
|
+
def initialize(refresh_rate, repository:)
|
17
|
+
@names = [].freeze
|
18
|
+
@refresher = Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
|
19
|
+
@names = repository.to_a.freeze
|
20
|
+
end
|
24
21
|
end
|
25
22
|
|
23
|
+
# @overload each
|
24
|
+
# @return [Enumerator<String>]
|
25
|
+
#
|
26
|
+
# @overload each(&block)
|
27
|
+
# For a block { |queue_name| ... }
|
28
|
+
# @yieldparam queue_name [String]
|
29
|
+
# @return [self]
|
26
30
|
def each(&block)
|
27
31
|
return to_enum __method__ unless block
|
28
32
|
|
29
33
|
start_refresher unless refresher_running?
|
30
|
-
@
|
31
|
-
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param name [#to_s]
|
36
|
-
# @return [Queues] self
|
37
|
-
def pause!(name)
|
38
|
-
redis_call("SADD", Pauzer::REDIS_KEY, name.to_s)
|
39
|
-
refresh
|
40
|
-
self
|
41
|
-
end
|
34
|
+
@names.each(&block)
|
42
35
|
|
43
|
-
# @param name [#to_s]
|
44
|
-
# @return [Queues] self
|
45
|
-
def unpause!(name)
|
46
|
-
redis_call("SREM", Pauzer::REDIS_KEY, name.to_s)
|
47
|
-
refresh
|
48
36
|
self
|
49
37
|
end
|
50
38
|
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
include?(name.to_s)
|
55
|
-
end
|
56
|
-
|
39
|
+
# Starts paused queues list async poller.
|
40
|
+
#
|
41
|
+
# @return [self]
|
57
42
|
def start_refresher
|
58
|
-
@
|
59
|
-
@refresher&.shutdown
|
60
|
-
@refresher = Concurrent::TimerTask.execute(execution_interval: refresh_rate, run_now: true) { refresh }
|
61
|
-
end
|
62
|
-
|
43
|
+
@refresher.execute
|
63
44
|
self
|
64
45
|
end
|
65
46
|
|
47
|
+
# Stops paused queues list async poller.
|
48
|
+
#
|
49
|
+
# @return [self]
|
66
50
|
def stop_refresher
|
67
|
-
@
|
68
|
-
@refresher&.shutdown
|
69
|
-
@refresher = nil
|
70
|
-
end
|
71
|
-
|
51
|
+
@refresher.shutdown
|
72
52
|
self
|
73
53
|
end
|
74
54
|
|
75
55
|
def refresher_running?
|
76
|
-
@
|
77
|
-
@refresher&.running? || false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
# @return [nil]
|
84
|
-
def refresh
|
85
|
-
names = redis_call("SMEMBERS", Pauzer::REDIS_KEY).to_a
|
86
|
-
|
87
|
-
@names_mutex.synchronize do
|
88
|
-
@names = names.each(&:freeze).freeze
|
89
|
-
end
|
90
|
-
|
91
|
-
nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def redis_call(...)
|
95
|
-
Sidekiq.redis { |conn| conn.call(...) }
|
56
|
+
@refresher.running?
|
96
57
|
end
|
97
58
|
end
|
98
59
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Pauzer
|
5
|
+
class Repository
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
REDIS_KEY = "sidekiq-pauzer"
|
9
|
+
|
10
|
+
# @overload each
|
11
|
+
# @return [Enumerator<String>]
|
12
|
+
#
|
13
|
+
# @overload each(&block)
|
14
|
+
# For a block { |queue_name| ... }
|
15
|
+
# @yieldparam queue_name [String]
|
16
|
+
# @return [self]
|
17
|
+
def each
|
18
|
+
return to_enum __method__ unless block_given?
|
19
|
+
|
20
|
+
redis_call("SMEMBERS", REDIS_KEY).each { yield _1.freeze }
|
21
|
+
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param queue_name [#to_s]
|
26
|
+
# @return [void]
|
27
|
+
def add(queue_name)
|
28
|
+
redis_call("SADD", REDIS_KEY, queue_name.to_s)
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param queue_name [#to_s]
|
33
|
+
# @return [void]
|
34
|
+
def delete(queue_name)
|
35
|
+
redis_call("SREM", REDIS_KEY, queue_name.to_s)
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param name [#to_s]
|
40
|
+
# @return [void]
|
41
|
+
def include?(queue_name)
|
42
|
+
redis_call("SISMEMBER", REDIS_KEY, queue_name.to_s).positive?
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def redis_call(...)
|
48
|
+
Sidekiq.redis { _1.call(...) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sidekiq/pauzer.rb
CHANGED
@@ -1,52 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "forwardable"
|
4
3
|
require "sidekiq"
|
5
4
|
require "sidekiq/api"
|
6
5
|
|
7
|
-
require_relative "./pauzer/config"
|
8
|
-
require_relative "./pauzer/patches/basic_fetch"
|
9
|
-
require_relative "./pauzer/patches/queue"
|
10
|
-
require_relative "./pauzer/queues"
|
11
|
-
require_relative "./pauzer/version"
|
12
|
-
|
13
6
|
begin
|
7
|
+
# :nocov:
|
14
8
|
require "sidekiq-ent/version"
|
9
|
+
raise "sidekiq-pauzer is incompatible with Sidekiq Enterprise"
|
10
|
+
# :nocov:
|
15
11
|
rescue LoadError
|
16
12
|
# All good - no compatibility issues
|
17
13
|
end
|
18
14
|
|
19
15
|
begin
|
16
|
+
# :nocov:
|
20
17
|
require "sidekiq/pro/version"
|
18
|
+
raise "sidekiq-pauzer is incompatible with Sidekiq Pro"
|
19
|
+
# :nocov:
|
21
20
|
rescue LoadError
|
22
21
|
# All good - no compatibility issues
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
24
|
+
require_relative "./pauzer/config"
|
25
|
+
require_relative "./pauzer/patches/basic_fetch"
|
26
|
+
require_relative "./pauzer/patches/queue"
|
27
|
+
require_relative "./pauzer/queues"
|
28
|
+
require_relative "./pauzer/repository"
|
29
|
+
require_relative "./pauzer/version"
|
27
30
|
|
28
31
|
module Sidekiq
|
29
32
|
module Pauzer
|
30
|
-
REDIS_KEY = "sidekiq-pauzer"
|
31
|
-
|
32
33
|
MUTEX = Mutex.new
|
33
34
|
private_constant :MUTEX
|
34
35
|
|
35
|
-
@config
|
36
|
-
@
|
36
|
+
@config = Config.new.freeze
|
37
|
+
@repository = Repository.new
|
38
|
+
@queues = Queues.new(@config.refresh_rate, repository: @repository)
|
37
39
|
|
38
40
|
class << self
|
39
|
-
extend Forwardable
|
40
|
-
|
41
41
|
# @example
|
42
42
|
# Sidekiq::Pauzer.pause!("minor")
|
43
43
|
# Sidekiq::Pauzer.paused?("minor") # => true
|
44
44
|
#
|
45
|
-
# @param (see
|
45
|
+
# @param (see Repository#add)
|
46
46
|
# @return [void]
|
47
|
-
def pause!(
|
48
|
-
@
|
49
|
-
|
47
|
+
def pause!(queue_name)
|
48
|
+
@repository.add(queue_name)
|
50
49
|
nil
|
51
50
|
end
|
52
51
|
|
@@ -56,11 +55,10 @@ module Sidekiq
|
|
56
55
|
# Sidekiq::Pauzer.unpause!("minor")
|
57
56
|
# Sidekiq::Pauzer.paused?("minor") # => false
|
58
57
|
#
|
59
|
-
# @param (see
|
58
|
+
# @param (see Repository#delete)
|
60
59
|
# @return [void]
|
61
|
-
def unpause!(
|
62
|
-
@
|
63
|
-
|
60
|
+
def unpause!(queue_name)
|
61
|
+
@repository.delete(queue_name)
|
64
62
|
nil
|
65
63
|
end
|
66
64
|
|
@@ -69,11 +67,13 @@ module Sidekiq
|
|
69
67
|
# Sidekiq::Pauzer.paused?("minor") # => true
|
70
68
|
# Sidekiq::Pauzer.paused?("threat") # => false
|
71
69
|
#
|
72
|
-
# @see
|
73
|
-
def paused?(
|
74
|
-
@
|
70
|
+
# @return (see Repository#include?)
|
71
|
+
def paused?(queue_name)
|
72
|
+
@repository.include?(queue_name)
|
75
73
|
end
|
76
74
|
|
75
|
+
# Eventually consistent list of paused queues.
|
76
|
+
#
|
77
77
|
# @example
|
78
78
|
# Sidekiq::Pauzer.pause!("minor")
|
79
79
|
# Sidekiq::Pauzer.paused_queues # => ["minor"]
|
@@ -121,7 +121,7 @@ module Sidekiq
|
|
121
121
|
|
122
122
|
def reinit_queues
|
123
123
|
@queues.stop_refresher
|
124
|
-
@queues = Queues.new(@config)
|
124
|
+
@queues = Queues.new(@config.refresh_rate, repository: @repository)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
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: 5.
|
4
|
+
version: 5.1.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-12-
|
11
|
+
date: 2023-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/sidekiq/pauzer/patches/web_action.rb
|
56
56
|
- lib/sidekiq/pauzer/patches/web_application.rb
|
57
57
|
- lib/sidekiq/pauzer/queues.rb
|
58
|
+
- lib/sidekiq/pauzer/repository.rb
|
58
59
|
- lib/sidekiq/pauzer/version.rb
|
59
60
|
- lib/sidekiq/pauzer/web.rb
|
60
61
|
- web/views/queues.erb
|
@@ -63,9 +64,9 @@ licenses:
|
|
63
64
|
- MIT
|
64
65
|
metadata:
|
65
66
|
homepage_uri: https://github.com/ixti/sidekiq-pauzer
|
66
|
-
source_code_uri: https://github.com/ixti/sidekiq-pauzer/tree/v5.
|
67
|
+
source_code_uri: https://github.com/ixti/sidekiq-pauzer/tree/v5.1.0
|
67
68
|
bug_tracker_uri: https://github.com/ixti/sidekiq-pauzer/issues
|
68
|
-
changelog_uri: https://github.com/ixti/sidekiq-pauzer/blob/v5.
|
69
|
+
changelog_uri: https://github.com/ixti/sidekiq-pauzer/blob/v5.1.0/CHANGES.md
|
69
70
|
rubygems_mfa_required: 'true'
|
70
71
|
post_install_message:
|
71
72
|
rdoc_options: []
|