sidekiq_alive 2.0.4 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf273df09ffb9644877ecc5966a9c7e94615d491b13a79c8b1dc50a298188cd
4
- data.tar.gz: f5f6aed93f4504d8ddb2b0b38a24841a93110e09392d08d8e5639458cf505e85
3
+ metadata.gz: cbebd769f1de056322e4efcae5e38a6ec9f6257dc7b66e7c01ed8383c3f92159
4
+ data.tar.gz: c17640dff13d58911b06c27ec262718050f949dd649aa4ca70d113aeb04ff99d
5
5
  SHA512:
6
- metadata.gz: 18a60ff3d82051ca24831b886a7b1a98be6c8121f89d13a25fc2b875357de615afd6620a80e9ed36f99d4b5b48a48eb3172f01548306d7658fcb0f80650d0ec8
7
- data.tar.gz: 7365d0aadc34ea188ff9a268222e2c7b7d21840f527f5444653fba72f9fdb3cd5184c5268b66590e8d2f8bacac85884c2a7ed7b0423d9920654372066fc37f58
6
+ metadata.gz: 101e33628eb65ed68b753d7d7fd6704176895c80085e18d0a72c4eee80d08f331d2533de0853c708de9f716f694d09219baaf16805c2d36b854473c04ef0f010
7
+ data.tar.gz: 351477e70c6480d85fc035d82b46f294b2da82ea6faac039754c26c388aa9db24ecedb14f867ad5793effcd240d7c50852fbdabe52fc26da1c07d1026e7f1fa1
@@ -0,0 +1,41 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby-version: [3.0.x, 2.7.x, 2.6.x, 2.5.x]
16
+ # Service containers to run with `runner-job`
17
+ services:
18
+ # Label used to access the service container
19
+ redis:
20
+ # Docker Hub image
21
+ image: redis
22
+ # Set health checks to wait until redis has started
23
+ options: >-
24
+ --health-cmd "redis-cli ping"
25
+ --health-interval 10s
26
+ --health-timeout 5s
27
+ --health-retries 5
28
+ ports:
29
+ # Maps port 6379 on service container to the host
30
+ - 6379:6379
31
+
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ - name: Set up Ruby ${{ matrix.ruby-version }}
35
+ uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
36
+ with:
37
+ ruby-version: ${{ matrix.ruby-version }}
38
+ - name: Install dependencies
39
+ run: bundle install
40
+ - name: Run tests
41
+ run: bundle exec rspec
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq_alive (2.0.4)
4
+ sidekiq_alive (2.1.1)
5
5
  sidekiq
6
6
 
7
7
  GEM
@@ -15,12 +15,12 @@ GEM
15
15
  pry (0.12.2)
16
16
  coderay (~> 1.1.0)
17
17
  method_source (~> 0.9.0)
18
- rack (2.0.6)
18
+ rack (2.2.3)
19
19
  rack-protection (2.0.5)
20
20
  rack
21
21
  rack-test (1.1.0)
22
22
  rack (>= 1.0, < 3)
23
- rake (10.5.0)
23
+ rake (13.0.3)
24
24
  redis (4.1.0)
25
25
  rspec (3.8.0)
26
26
  rspec-core (~> 3.8.0)
@@ -48,14 +48,14 @@ PLATFORMS
48
48
  ruby
49
49
 
50
50
  DEPENDENCIES
51
- bundler (~> 1.16)
51
+ bundler (> 1.16)
52
52
  mock_redis
53
53
  pry
54
54
  rack-test
55
- rake (~> 10.0)
55
+ rake (~> 13.0)
56
56
  rspec (~> 3.0)
57
57
  rspec-sidekiq (~> 3.0)
58
58
  sidekiq_alive!
59
59
 
60
60
  BUNDLED WITH
61
- 1.17.3
61
+ 2.2.22
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  SidekiqAlive offers a solution to add liveness probe for a Sidekiq instance deployed in Kubernetes.
8
8
  This library can be used to check sidekiq health outside kubernetes.
9
9
 
10
- __How?__
10
+ **How?**
11
11
 
12
12
  A http server is started and on each requests validates that a liveness key is stored in Redis. If it is there means is working.
13
13
 
@@ -52,7 +52,6 @@ Or install it yourself as:
52
52
 
53
53
  $ gem install sidekiq_alive
54
54
 
55
-
56
55
  ## Usage
57
56
 
58
57
  SidekiqAlive will start when running `sidekiq` command.
@@ -68,8 +67,7 @@ curl localhost:7433
68
67
  #=> Alive!
69
68
  ```
70
69
 
71
-
72
- __how to disable?__
70
+ **how to disable?**
73
71
  You can disabled by setting `ENV` variable `DISABLE_SIDEKIQ_ALIVE`
74
72
  example:
75
73
 
@@ -115,7 +113,7 @@ spec:
115
113
  preStop:
116
114
  exec:
117
115
  # SIGTERM triggers a quick exit; gracefully terminate instead
118
- command: ["bundle", "exec", "sidekiqctl", "quiet"]
116
+ command: ['bundle', 'exec', 'sidekiqctl', 'quiet']
119
117
  terminationGracePeriodSeconds: 60 # put your longest Job time here plus security time.
120
118
  ```
121
119
 
@@ -172,7 +170,7 @@ spec:
172
170
  preStop:
173
171
  exec:
174
172
  # SIGTERM triggers a quick exit; gracefully terminate instead
175
- command: ["kube/sidekiq_quiet"]
173
+ command: ['kube/sidekiq_quiet']
176
174
  terminationGracePeriodSeconds: 60 # put your longest Job time here plus security time.
177
175
  ```
178
176
 
@@ -196,6 +194,13 @@ curl localhost:7433
196
194
 
197
195
  ```ruby
198
196
  SidekiqAlive.setup do |config|
197
+ # ==> Server host
198
+ # Host to bind the server.
199
+ # Can also be set with the environment variable SIDEKIQ_ALIVE_HOST.
200
+ # default: 0.0.0.0
201
+ #
202
+ # config.host = 0.0.0.0
203
+
199
204
  # ==> Server port
200
205
  # Port to bind the server.
201
206
  # Can also be set with the environment variable SIDEKIQ_ALIVE_PORT.
@@ -210,6 +215,13 @@ SidekiqAlive.setup do |config|
210
215
  #
211
216
  # config.path = '/'
212
217
 
218
+ # ==> Custom Liveness Probe
219
+ # Extra check to decide if restart the pod or not for example connection to DB.
220
+ # `false`, `nil` or `raise` will not write the liveness probe
221
+ # default: proc { true }
222
+ #
223
+ # config.custom_liveness_probe = proc { db_running? }
224
+
213
225
  # ==> Liveness key
214
226
  # Key to be stored in Redis as probe of liveness
215
227
  # default: "SIDEKIQ::LIVENESS_PROBE_TIMESTAMP"
@@ -0,0 +1,6 @@
1
+ version: '3.6'
2
+ services:
3
+ redis:
4
+ image: redis
5
+ ports:
6
+ - 6379:6379
data/lib/sidekiq_alive.rb CHANGED
@@ -52,7 +52,14 @@ module SidekiqAlive
52
52
  end
53
53
 
54
54
  def self.registered_instances
55
- redis.keys("#{config.registered_instance_key}::*")
55
+ deep_scan("#{config.registered_instance_key}::*")
56
+ end
57
+
58
+ def self.deep_scan(keyword, keys = [], cursor = 0)
59
+ next_cursor, found_keys = *redis { |r| r }.scan(cursor, match: keyword)
60
+ keys += found_keys
61
+ return keys if next_cursor == "0" || found_keys.blank?
62
+ deep_scan(keyword, keys, next_cursor)
56
63
  end
57
64
 
58
65
  def self.purge_pending_jobs
@@ -4,20 +4,23 @@ module SidekiqAlive
4
4
  class Config
5
5
  include Singleton
6
6
 
7
- attr_accessor :port,
7
+ attr_accessor :host,
8
+ :port,
8
9
  :path,
9
10
  :liveness_key,
10
11
  :time_to_live,
11
12
  :callback,
12
13
  :registered_instance_key,
13
14
  :queue_prefix,
14
- :server
15
+ :server,
16
+ :custom_liveness_probe
15
17
 
16
18
  def initialize
17
19
  set_defaults
18
20
  end
19
21
 
20
22
  def set_defaults
23
+ @host = ENV['SIDEKIQ_ALIVE_HOST'] || '0.0.0.0'
21
24
  @port = ENV['SIDEKIQ_ALIVE_PORT'] || 7433
22
25
  @path = ENV['SIDEKIQ_ALIVE_PATH'] || '/'
23
26
  @liveness_key = 'SIDEKIQ::LIVENESS_PROBE_TIMESTAMP'
@@ -26,6 +29,7 @@ module SidekiqAlive
26
29
  @registered_instance_key = 'SIDEKIQ_REGISTERED_INSTANCE'
27
30
  @queue_prefix = :sidekiq_alive
28
31
  @server = ENV['SIDEKIQ_ALIVE_SERVER'] || 'webrick'
32
+ @custom_liveness_probe = proc { true }
29
33
  end
30
34
 
31
35
  def registration_ttl
@@ -10,7 +10,11 @@ module SidekiqAlive
10
10
 
11
11
  Signal.trap('TERM') { handler.shutdown }
12
12
 
13
- handler.run(self, Port: port, Host: '0.0.0.0')
13
+ handler.run(self, Port: port, Host: '0.0.0.0', AccessLog: [])
14
+ end
15
+
16
+ def host
17
+ SidekiqAlive.config.host
14
18
  end
15
19
 
16
20
  def port
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqAlive
4
- VERSION = '2.0.4'
4
+ VERSION = '2.1.1'
5
5
  end
@@ -1,11 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SidekiqAlive
2
4
  class Worker
3
5
  include Sidekiq::Worker
4
6
  sidekiq_options retry: false
5
7
 
6
8
  def perform(_hostname = SidekiqAlive.hostname)
9
+ # Checks if custom liveness probe passes should fail or return false
10
+ return unless config.custom_liveness_probe.call
11
+
12
+ # Writes the liveness in Redis
7
13
  write_living_probe
8
- # schedule next living probe
14
+ # schedules next living probe
9
15
  self.class.perform_in(config.time_to_live / 2, current_hostname)
10
16
  end
11
17
 
@@ -29,10 +29,10 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_development_dependency 'bundler', '~> 1.16'
32
+ spec.add_development_dependency 'bundler', '> 1.16'
33
33
  spec.add_development_dependency 'mock_redis'
34
34
  spec.add_development_dependency 'rack-test'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
37
  spec.add_development_dependency 'rspec-sidekiq', '~> 3.0'
38
38
  spec.add_dependency 'sidekiq'
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_alive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Pañach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.16'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -125,8 +125,10 @@ executables: []
125
125
  extensions: []
126
126
  extra_rdoc_files: []
127
127
  files:
128
+ - ".github/workflows/test.yml"
128
129
  - ".gitignore"
129
130
  - ".rspec"
131
+ - ".tool-versions"
130
132
  - ".travis.yml"
131
133
  - CODE_OF_CONDUCT.md
132
134
  - Gemfile
@@ -136,6 +138,7 @@ files:
136
138
  - Rakefile
137
139
  - bin/console
138
140
  - bin/setup
141
+ - docker-compose.yml
139
142
  - lib/sidekiq_alive.rb
140
143
  - lib/sidekiq_alive/config.rb
141
144
  - lib/sidekiq_alive/server.rb
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  requirements: []
164
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.6
165
168
  signing_key:
166
169
  specification_version: 4
167
170
  summary: Liveness probe for sidekiq on Kubernetes deployments.