sidekiq_alive 2.0.5 → 2.1.2

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: e6d5a90f1ac023c49440e1e24d53e05bd3fe1f5362822e125a8989981e51846e
4
- data.tar.gz: dd90cc1b6d7b1fc6273426e32f950d68a71eaa7d63b42b32d914450f35eec09a
3
+ metadata.gz: '08d38ee6866d0c487f93b13d5c4fc64d70d5775efbf29e1c44e3e6d0a968ec0c'
4
+ data.tar.gz: 2d5955184dd20b771897edf42f23471023faa95ed19ffea0850ef9ca086d7193
5
5
  SHA512:
6
- metadata.gz: 533ef08f31e90ac4743577c561f3994c2b2e7eb9945cadcc4dc70dda3e2b339d8d8e6ab2d270b82a65dc884812b8d30ce1de49e50648af1a4136eafa77ee9dd3
7
- data.tar.gz: 702c96b61ecaa7595b44ff9bd3dcfa29d58e99623a5fcd5534b94221dd92e96b06e0e81f217c826f7d8ee9e75bee55ef063d93ff855381efa5ead8af96a01cc4
6
+ metadata.gz: c9e8b6b12990a57f4075b7e8b79d8006c399240e0d17fb678437bf6fc8798164502761f3920543ca351a2248bcd1cefc57e0bf9d105da951b1942fd78a440dad
7
+ data.tar.gz: a0bbe436f1ca6e2601d2dd3daa7f321c6ddbcf6e69f51b3a222daedeb8c2f4b3b5bffde590b68ffcba43a179877d5694459ea7bf5cf9cef295fed27164d378d7
@@ -0,0 +1,48 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [master]
13
+ pull_request:
14
+ branches: [master]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ["2.6", "2.7", "3.0"]
22
+ services:
23
+ # Label used to access the service container
24
+ redis:
25
+ # Docker Hub image
26
+ image: redis
27
+ # Set health checks to wait until redis has started
28
+ options: >-
29
+ --health-cmd "redis-cli ping"
30
+ --health-interval 10s
31
+ --health-timeout 5s
32
+ --health-retries 5
33
+ ports:
34
+ # Maps port 6379 on service container to the host
35
+ - 6379:6379
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+ - name: Set up Ruby
40
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
41
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
42
+ # uses: ruby/setup-ruby@v1
43
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
44
+ with:
45
+ ruby-version: ${{ matrix.ruby-version }}
46
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
47
+ - name: Run tests
48
+ run: bundle exec rake
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.5)
4
+ sidekiq_alive (2.1.2)
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
@@ -1,13 +1,13 @@
1
1
  # SidekiqAlive
2
2
 
3
- [![Build Status](https://travis-ci.org/arturictus/sidekiq_alive.svg?branch=master)](https://travis-ci.org/arturictus/sidekiq_alive)
3
+ ![build](https://github.com/arturictus/sidekiq_alive/actions/workflows/ruby.yml/badge.svg)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/35c39124564ffeb0ce4e/maintainability)](https://codeclimate.com/github/arturictus/sidekiq_alive/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/35c39124564ffeb0ce4e/test_coverage)](https://codeclimate.com/github/arturictus/sidekiq_alive/test_coverage)
6
6
 
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
 
@@ -217,6 +215,13 @@ SidekiqAlive.setup do |config|
217
215
  #
218
216
  # config.path = '/'
219
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
+
220
225
  # ==> Liveness key
221
226
  # Key to be stored in Redis as probe of liveness
222
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
@@ -156,4 +163,4 @@ end
156
163
  require 'sidekiq_alive/worker'
157
164
  require 'sidekiq_alive/server'
158
165
 
159
- SidekiqAlive.start unless ENV['DISABLE_SIDEKIQ_ALIVE']
166
+ SidekiqAlive.start unless ENV.fetch('DISABLE_SIDEKIQ_ALIVE', '').casecmp("true") == 0
@@ -12,22 +12,24 @@ module SidekiqAlive
12
12
  :callback,
13
13
  :registered_instance_key,
14
14
  :queue_prefix,
15
- :server
15
+ :server,
16
+ :custom_liveness_probe
16
17
 
17
18
  def initialize
18
19
  set_defaults
19
20
  end
20
21
 
21
22
  def set_defaults
22
- @host = ENV['SIDEKIQ_ALIVE_HOST'] || '0.0.0.0'
23
- @port = ENV['SIDEKIQ_ALIVE_PORT'] || 7433
24
- @path = ENV['SIDEKIQ_ALIVE_PATH'] || '/'
23
+ @host = ENV.fetch('SIDEKIQ_ALIVE_HOST', '0.0.0.0')
24
+ @port = ENV.fetch('SIDEKIQ_ALIVE_PORT', 7433)
25
+ @path = ENV.fetch('SIDEKIQ_ALIVE_PATH', '/')
25
26
  @liveness_key = 'SIDEKIQ::LIVENESS_PROBE_TIMESTAMP'
26
27
  @time_to_live = 10 * 60
27
28
  @callback = proc {}
28
29
  @registered_instance_key = 'SIDEKIQ_REGISTERED_INSTANCE'
29
30
  @queue_prefix = :sidekiq_alive
30
- @server = ENV['SIDEKIQ_ALIVE_SERVER'] || 'webrick'
31
+ @server = ENV.fetch('SIDEKIQ_ALIVE_SERVER', 'webrick')
32
+ @custom_liveness_probe = proc { true }
31
33
  end
32
34
 
33
35
  def registration_ttl
@@ -10,7 +10,7 @@ module SidekiqAlive
10
10
 
11
11
  Signal.trap('TERM') { handler.shutdown }
12
12
 
13
- handler.run(self, Port: port, Host: host)
13
+ handler.run(self, Port: port, Host: '0.0.0.0', AccessLog: [])
14
14
  end
15
15
 
16
16
  def host
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqAlive
4
- VERSION = '2.0.5'
4
+ VERSION = '2.1.2'
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.5
4
+ version: 2.1.2
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: 2021-03-29 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/ruby.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.