sidekiq_alive 2.1.6 → 2.1.8

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: 76f6e9a464393aa3302fbac6d7baf2e58338fe8326101d644a6a3d963dd38305
4
- data.tar.gz: 781f50dd5cf55b17421b287ce56c193baf33a99cb504290592643bdf79a0078b
3
+ metadata.gz: '070807205b4f9046f51b90908873679c0cd716d1beff188b8d9f275b18f77594'
4
+ data.tar.gz: 60b050e4a93a3e98602e96c221b50e2398f7d40e2d7358c3c80429f59d0830fb
5
5
  SHA512:
6
- metadata.gz: 62ca85ef26fa1b6991a06ec7095a38280bd6165111b0897e9fa52e83e09a806c6bd125de6233084b559f216c831d8cc4735fb4f84b720cc1f46916b63eeb52ef
7
- data.tar.gz: 5579938e0bbf3a79d727d651fab8167d06e83d480bd145efcf1f2d6fb3b896e07cf3555be77ae5376f9af5bc2164fbce6acf8dcffb84e156d9d118e9dccf3c2c
6
+ metadata.gz: cb15f99935b3ef0f0c4bc297e07d741b3f0bd3dbefbe72a19cfcc512098117317405f54372adfc10577a233f9e70c05ad8288ec1a6c1323e5499214dc3888132
7
+ data.tar.gz: b99e019282d2b9313b1ccd32cd151da5ebfc1ba30f2c335b03de16e38689d412fa48f6c60fb70b453a65fb97faa1c1867fdf733603d7e46b7547966f1cd26889
data/README.md CHANGED
@@ -244,11 +244,19 @@ SidekiqAlive.setup do |config|
244
244
  # require 'net/http'
245
245
  # config.callback = proc { Net::HTTP.get("https://status.com/ping") }
246
246
 
247
+ # ==> Shutdown callback
248
+ # When sidekiq process is shutting down, you can perform some action, like cleaning up created queue
249
+ # default: proc {}
250
+ #
251
+ # config.shutdown_callback = proc do
252
+ # Sidekiq::Queue.all.find { |q| q.name == "#{queue_prefix}-#{SidekiqAlive.hostname}" }&.clear
253
+ # end
254
+
247
255
  # ==> Queue Prefix
248
256
  # SidekiqAlive will run in a independent queue for each instance/replica
249
257
  # This queue name will be generated with: "#{queue_prefix}-#{hostname}.
250
258
  # You can customize the prefix here.
251
- # default: :sidekiq_alive
259
+ # default: :sidekiq-alive
252
260
  #
253
261
  # config.queue_prefix = :other
254
262
 
@@ -13,23 +13,26 @@ module SidekiqAlive
13
13
  :registered_instance_key,
14
14
  :queue_prefix,
15
15
  :server,
16
- :custom_liveness_probe
16
+ :custom_liveness_probe,
17
+ :logger,
18
+ :shutdown_callback
17
19
 
18
20
  def initialize
19
21
  set_defaults
20
22
  end
21
23
 
22
24
  def set_defaults
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', '/')
26
- @liveness_key = 'SIDEKIQ::LIVENESS_PROBE_TIMESTAMP'
25
+ @host = ENV.fetch("SIDEKIQ_ALIVE_HOST", "0.0.0.0")
26
+ @port = ENV.fetch("SIDEKIQ_ALIVE_PORT", 7433)
27
+ @path = ENV.fetch("SIDEKIQ_ALIVE_PATH", "/")
28
+ @liveness_key = "SIDEKIQ::LIVENESS_PROBE_TIMESTAMP"
27
29
  @time_to_live = 10 * 60
28
30
  @callback = proc {}
29
- @registered_instance_key = 'SIDEKIQ_REGISTERED_INSTANCE'
30
- @queue_prefix = :sidekiq_alive
31
- @server = ENV.fetch('SIDEKIQ_ALIVE_SERVER', 'webrick')
31
+ @registered_instance_key = "SIDEKIQ_REGISTERED_INSTANCE"
32
+ @queue_prefix = :"sidekiq-alive"
33
+ @server = ENV.fetch("SIDEKIQ_ALIVE_SERVER", "webrick")
32
34
  @custom_liveness_probe = proc { true }
35
+ @shutdown_callback = proc {}
33
36
  end
34
37
 
35
38
  def registration_ttl
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqAlive
4
+ module Helpers
5
+ class << self
6
+ def sidekiq_7
7
+ current_sidekiq_version >= Gem::Version.new("7")
8
+ end
9
+
10
+ def sidekiq_6
11
+ current_sidekiq_version >= Gem::Version.new("6") &&
12
+ current_sidekiq_version < Gem::Version.new("7")
13
+ end
14
+
15
+ def sidekiq_5
16
+ current_sidekiq_version >= Gem::Version.new("5") &&
17
+ current_sidekiq_version < Gem::Version.new("6")
18
+ end
19
+
20
+ private
21
+
22
+ def current_sidekiq_version
23
+ Gem.loaded_specs["sidekiq"].version
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqAlive
4
+ module Redis
5
+ class Base
6
+ def set(key, time:, ex:)
7
+ raise("Implement me")
8
+ end
9
+
10
+ def match(key)
11
+ raise("Implement me")
12
+ end
13
+
14
+ def delete(key)
15
+ raise("Implement me")
16
+ end
17
+
18
+ def ttl(...)
19
+ redis.ttl(...)
20
+ end
21
+
22
+ def flushall
23
+ redis.flushall
24
+ end
25
+
26
+ private
27
+
28
+ def redis
29
+ Sidekiq.redis { |r| r }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module SidekiqAlive
6
+ module Redis
7
+ # Wrapper for redis client used by sidekiq < 7
8
+ #
9
+ class Client < Base
10
+ def set(key, time:, ex:)
11
+ redis.set(key, time, ex: ex)
12
+ end
13
+
14
+ def match(key)
15
+ keys = []
16
+ cursor = 0
17
+
18
+ loop do
19
+ cursor, found_keys = redis.scan(cursor, match: key, count: 1000)
20
+ keys += found_keys if found_keys
21
+ break if cursor.to_i == 0
22
+ end
23
+ keys
24
+ end
25
+
26
+ def delete(key)
27
+ redis.del(key)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module SidekiqAlive
6
+ module Redis
7
+ # Wrapper for redis client adapter used by sidekiq > 7
8
+ #
9
+ class ClientAdapter < Base
10
+ def set(key, time:, ex:)
11
+ redis.call("SET", key, time, ex: ex)
12
+ end
13
+
14
+ def match(key)
15
+ redis.scan("MATCH", key).map { |key| key }
16
+ end
17
+
18
+ def delete(key)
19
+ redis.call("DEL", key)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack'
3
+ require "rack"
4
4
 
5
5
  module SidekiqAlive
6
6
  class Server
7
7
  class << self
8
8
  def run!
9
- handler = Rack::Handler.get(server)
9
+ handler = Rack::Handler.get(server)
10
10
 
11
- Signal.trap('TERM') { handler.shutdown }
11
+ Signal.trap("TERM") { handler.shutdown }
12
12
 
13
13
  handler.run(self, Port: port, Host: host, AccessLog: [], Logger: SidekiqAlive.logger)
14
14
  end
@@ -31,9 +31,9 @@ module SidekiqAlive
31
31
 
32
32
  def call(env)
33
33
  if Rack::Request.new(env).path != path
34
- [404, {}, ['Not found']]
34
+ [404, {}, ["Not found"]]
35
35
  elsif SidekiqAlive.alive?
36
- [200, {}, ['Alive!']]
36
+ [200, {}, ["Alive!"]]
37
37
  else
38
38
  response = "Can't find the alive key"
39
39
  SidekiqAlive.logger.error(response)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqAlive
4
- VERSION = '2.1.6'
4
+ VERSION = "2.1.8"
5
5
  end
data/lib/sidekiq_alive.rb CHANGED
@@ -1,168 +1,150 @@
1
- require 'sidekiq'
2
- require 'sidekiq/api'
3
- require 'singleton'
4
- require 'sidekiq_alive/version'
5
- require 'sidekiq_alive/config'
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/api"
5
+ require "singleton"
6
+ require "sidekiq_alive/version"
7
+ require "sidekiq_alive/config"
8
+ require "sidekiq_alive/helpers"
9
+ require "sidekiq_alive/redis/client"
10
+ require "sidekiq_alive/redis/client_adapter"
6
11
 
7
12
  module SidekiqAlive
8
- def self.start
9
- SidekiqAlive::Worker.sidekiq_options queue: current_queue
10
- Sidekiq.configure_server do |sq_config|
11
-
12
- (sq_config.respond_to?(:[]) ? sq_config[:queues] : sq_config.options[:queues]).unshift(current_queue)
13
-
14
- sq_config.on(:startup) do
15
- SidekiqAlive.tap do |sa|
16
- sa.logger.info(banner)
17
- sa.register_current_instance
18
- sa.store_alive_key
19
- sa::Worker.perform_async(hostname)
20
- @server_pid = fork do
21
- sa::Server.run!
22
- end
23
- sa.logger.info(successful_startup_text)
13
+ class << self
14
+ def start
15
+ Sidekiq.configure_server do |sq_config|
16
+ sq_config.on(:startup) do
17
+ SidekiqAlive::Worker.sidekiq_options(queue: current_queue)
18
+ if Helpers.sidekiq_7
19
+ sq_config.queues
20
+ else
21
+ sq_config.respond_to?(:[]) ? sq_config[:queues] : sq_config.options[:queues]
22
+ end.unshift(current_queue)
23
+
24
+ logger.info(startup_info)
25
+
26
+ register_current_instance
27
+ store_alive_key
28
+ SidekiqAlive::Worker.perform_async(hostname)
29
+ @server_pid = fork { SidekiqAlive::Server.run! }
30
+
31
+ logger.info(successful_startup_text)
24
32
  end
25
- end
26
33
 
27
- sq_config.on(:quiet) do
28
- SidekiqAlive.unregister_current_instance
29
- end
34
+ sq_config.on(:quiet) do
35
+ unregister_current_instance
36
+ config.shutdown_callback.call
37
+ end
30
38
 
31
- sq_config.on(:shutdown) do
32
- Process.kill('TERM', @server_pid) unless @server_pid.nil?
33
- Process.wait(@server_pid) unless @server_pid.nil?
34
- SidekiqAlive.unregister_current_instance
39
+ sq_config.on(:shutdown) do
40
+ Process.kill("TERM", @server_pid) unless @server_pid.nil?
41
+ Process.wait(@server_pid) unless @server_pid.nil?
42
+
43
+ unregister_current_instance
44
+ config.shutdown_callback.call
45
+ end
35
46
  end
36
47
  end
37
- end
38
-
39
- def self.current_queue
40
- "#{config.queue_prefix}-#{hostname}"
41
- end
42
-
43
- def self.register_current_instance
44
- register_instance(current_instance_register_key)
45
- end
46
-
47
- def self.unregister_current_instance
48
- # Delete any pending jobs for this instance
49
- logger.info(shutdown_info)
50
- purge_pending_jobs
51
- redis.del(current_instance_register_key)
52
- end
53
48
 
54
- def self.registered_instances
55
- deep_scan("#{config.registered_instance_key}::*")
56
- end
57
-
58
- def self.deep_scan(keyword, keys = [], cursor = 0)
59
- loop do
60
- cursor, found_keys = SidekiqAlive.redis.scan(cursor, match: keyword, count: 1000)
61
- keys += found_keys
62
- break if cursor.to_i == 0
49
+ def current_queue
50
+ "#{config.queue_prefix}-#{hostname}"
63
51
  end
64
- keys
65
- end
66
-
67
- def self.purge_pending_jobs
68
- # TODO:
69
- # Sidekiq 6 allows better way to find scheduled jobs:
70
- # https://github.com/mperham/sidekiq/wiki/API#scan
71
- scheduled_set = Sidekiq::ScheduledSet.new
72
- jobs = scheduled_set.select { |job| job.klass == 'SidekiqAlive::Worker' && job.queue == current_queue }
73
- logger.info("[SidekiqAlive] Purging #{jobs.count} pending for #{hostname}")
74
- jobs.each(&:delete)
75
- logger.info("[SidekiqAlive] Removing queue #{current_queue}")
76
- Sidekiq::Queue.new(current_queue).clear
77
- end
78
-
79
- def self.current_instance_register_key
80
- "#{config.registered_instance_key}::#{hostname}"
81
- end
82
-
83
- def self.store_alive_key
84
- redis.set(current_lifeness_key,
85
- Time.now.to_i,
86
- ex: config.time_to_live.to_i)
87
- end
88
-
89
- def self.redis
90
- Sidekiq.redis { |r| r }
91
- end
92
-
93
- def self.alive?
94
- redis.ttl(current_lifeness_key) != -2
95
- end
96
52
 
97
- # CONFIG ---------------------------------------
53
+ def register_current_instance
54
+ register_instance(current_instance_register_key)
55
+ end
98
56
 
99
- def self.setup
100
- yield(config)
101
- end
57
+ def unregister_current_instance
58
+ # Delete any pending jobs for this instance
59
+ logger.info(shutdown_info)
60
+ purge_pending_jobs
61
+ redis.delete(current_instance_register_key)
62
+ end
102
63
 
103
- def self.logger
104
- Sidekiq.logger
105
- end
64
+ def registered_instances
65
+ redis.match("#{config.registered_instance_key}::*")
66
+ end
106
67
 
107
- def self.config
108
- @config ||= SidekiqAlive::Config.instance
109
- end
68
+ def purge_pending_jobs
69
+ schedule_set = Sidekiq::ScheduledSet.new
70
+ jobs = if Helpers.sidekiq_5
71
+ schedule_set.select { |job| job.klass == "SidekiqAlive::Worker" && job.queue == current_queue }
72
+ else
73
+ schedule_set.scan('"class":"SidekiqAlive::Worker"')
74
+ end
75
+ logger.info("[SidekiqAlive] Purging #{jobs.count} pending for #{hostname}")
76
+ jobs.each(&:delete)
110
77
 
111
- def self.current_lifeness_key
112
- "#{config.liveness_key}::#{hostname}"
113
- end
78
+ logger.info("[SidekiqAlive] Removing queue #{current_queue}")
79
+ Sidekiq::Queue.new(current_queue).clear
80
+ end
114
81
 
115
- def self.hostname
116
- ENV['HOSTNAME'] || 'HOSTNAME_NOT_SET'
117
- end
82
+ def current_instance_register_key
83
+ "#{config.registered_instance_key}::#{hostname}"
84
+ end
118
85
 
119
- def self.shutdown_info
120
- <<~BANNER
86
+ def store_alive_key
87
+ redis.set(current_lifeness_key, time: Time.now.to_i, ex: config.time_to_live.to_i)
88
+ end
121
89
 
122
- =================== Shutting down SidekiqAlive =================
90
+ def redis
91
+ @redis ||= Helpers.sidekiq_7 ? Redis::ClientAdapter.new : Redis::Client.new
92
+ end
123
93
 
124
- Hostname: #{hostname}
125
- Liveness key: #{current_lifeness_key}
126
- Current instance register key: #{current_instance_register_key}
94
+ def alive?
95
+ redis.ttl(current_lifeness_key) != -2
96
+ end
127
97
 
128
- BANNER
129
- end
98
+ # CONFIG ---------------------------------------
130
99
 
131
- def self.banner
132
- <<~BANNER
100
+ def setup
101
+ yield(config)
102
+ end
133
103
 
134
- =================== SidekiqAlive =================
104
+ def logger
105
+ config.logger || Sidekiq.logger
106
+ end
135
107
 
136
- Hostname: #{hostname}
137
- Liveness key: #{current_lifeness_key}
138
- Port: #{config.port}
139
- Time to live: #{config.time_to_live}s
140
- Current instance register key: #{current_instance_register_key}
141
- Worker running on queue: #{@queue}
108
+ def config
109
+ @config ||= SidekiqAlive::Config.instance
110
+ end
142
111
 
112
+ def current_lifeness_key
113
+ "#{config.liveness_key}::#{hostname}"
114
+ end
143
115
 
144
- starting ...
145
- BANNER
146
- end
116
+ def hostname
117
+ ENV["HOSTNAME"] || "HOSTNAME_NOT_SET"
118
+ end
147
119
 
148
- def self.successful_startup_text
149
- <<~BANNER
150
- Registered instances:
120
+ def shutdown_info
121
+ "Shutting down sidekiq-alive!"
122
+ end
151
123
 
152
- - #{registered_instances.join("\n\s\s- ")}
124
+ def startup_info
125
+ info = {
126
+ hostname: hostname,
127
+ port: config.port,
128
+ ttl: config.time_to_live,
129
+ queue: current_queue,
130
+ liveness_key: current_lifeness_key,
131
+ register_key: current_instance_register_key,
132
+ }
133
+
134
+ "Starting sidekiq-alive: #{info}"
135
+ end
153
136
 
154
- =================== SidekiqAlive Ready! =================
155
- BANNER
156
- end
137
+ def successful_startup_text
138
+ "Successfully started sidekiq-alive, registered instances: #{registered_instances.join("\n\s\s- ")}"
139
+ end
157
140
 
158
- def self.register_instance(instance_name)
159
- redis.set(instance_name,
160
- Time.now.to_i,
161
- ex: config.registration_ttl.to_i)
141
+ def register_instance(instance_name)
142
+ redis.set(instance_name, time: Time.now.to_i, ex: config.registration_ttl.to_i)
143
+ end
162
144
  end
163
145
  end
164
146
 
165
- require 'sidekiq_alive/worker'
166
- require 'sidekiq_alive/server'
147
+ require "sidekiq_alive/worker"
148
+ require "sidekiq_alive/server"
167
149
 
168
- SidekiqAlive.start unless ENV.fetch('DISABLE_SIDEKIQ_ALIVE', '').casecmp("true") == 0
150
+ SidekiqAlive.start unless ENV.fetch("DISABLE_SIDEKIQ_ALIVE", "").casecmp("true").zero?
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_alive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
+ - Andrejs Cunskis
7
8
  - Artur Pañach
8
- autorequire:
9
- bindir: exe
9
+ autorequire:
10
+ bindir: bin
10
11
  cert_chain: []
11
- date: 2022-12-07 00:00:00.000000000 Z
12
+ date: 2022-12-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -25,33 +26,33 @@ dependencies:
25
26
  - !ruby/object:Gem::Version
26
27
  version: '1.16'
27
28
  - !ruby/object:Gem::Dependency
28
- name: mock_redis
29
+ name: debug
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: '1.6'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '0'
41
+ version: '1.6'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rack-test
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '0'
48
+ version: 2.0.2
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ">="
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '0'
55
+ version: 2.0.2
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: rake
57
58
  requirement: !ruby/object:Gem::Requirement
@@ -94,75 +95,126 @@ dependencies:
94
95
  - - "~>"
95
96
  - !ruby/object:Gem::Version
96
97
  version: '3.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-shopify
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '2.10'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.10'
112
+ - !ruby/object:Gem::Dependency
113
+ name: solargraph
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.48.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 0.48.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: rack
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "<"
131
+ - !ruby/object:Gem::Version
132
+ version: '3'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "<"
138
+ - !ruby/object:Gem::Version
139
+ version: '3'
97
140
  - !ruby/object:Gem::Dependency
98
141
  name: sidekiq
99
142
  requirement: !ruby/object:Gem::Requirement
100
143
  requirements:
101
144
  - - ">="
102
145
  - !ruby/object:Gem::Version
103
- version: '0'
146
+ version: '5'
147
+ - - "<"
148
+ - !ruby/object:Gem::Version
149
+ version: '8'
104
150
  type: :runtime
105
151
  prerelease: false
106
152
  version_requirements: !ruby/object:Gem::Requirement
107
153
  requirements:
108
154
  - - ">="
109
155
  - !ruby/object:Gem::Version
110
- version: '0'
156
+ version: '5'
157
+ - - "<"
158
+ - !ruby/object:Gem::Version
159
+ version: '8'
111
160
  - !ruby/object:Gem::Dependency
112
161
  name: webrick
113
162
  requirement: !ruby/object:Gem::Requirement
114
163
  requirements:
115
164
  - - ">="
116
165
  - !ruby/object:Gem::Version
117
- version: '0'
166
+ version: '1'
167
+ - - "<"
168
+ - !ruby/object:Gem::Version
169
+ version: '2'
118
170
  type: :runtime
119
171
  prerelease: false
120
172
  version_requirements: !ruby/object:Gem::Requirement
121
173
  requirements:
122
174
  - - ">="
123
175
  - !ruby/object:Gem::Version
124
- version: '0'
125
- description: |-
176
+ version: '1'
177
+ - - "<"
178
+ - !ruby/object:Gem::Version
179
+ version: '2'
180
+ description: |
126
181
  SidekiqAlive offers a solution to add liveness probe of a Sidekiq instance.
127
182
 
128
- How?
183
+ How?
129
184
 
130
- 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.
185
+ 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.
131
186
 
132
- A Sidekiq job is the responsable to storing this key. If Sidekiq stops processing jobs
133
- this key gets expired by Redis an consequently the http server will return a 500 error.
187
+ A Sidekiq job is the responsable to storing this key. If Sidekiq stops processing jobs
188
+ this key gets expired by Redis an consequently the http server will return a 500 error.
134
189
 
135
- This Job is responsible to requeue itself for the next liveness probe.
190
+ This Job is responsible to requeue itself for the next liveness probe.
136
191
  email:
192
+ - andrejs.cunskis@gmail.com
137
193
  - arturictus@gmail.com
138
194
  executables: []
139
195
  extensions: []
140
196
  extra_rdoc_files: []
141
197
  files:
142
- - ".github/workflows/test.yml"
143
- - ".gitignore"
144
- - ".rspec"
145
- - ".tool-versions"
146
- - CODE_OF_CONDUCT.md
147
- - Gemfile
148
- - Gemfile.lock
149
- - LICENSE.txt
150
198
  - README.md
151
- - Rakefile
152
- - bin/console
153
- - bin/setup
154
- - docker-compose.yml
155
199
  - lib/sidekiq_alive.rb
156
200
  - lib/sidekiq_alive/config.rb
201
+ - lib/sidekiq_alive/helpers.rb
202
+ - lib/sidekiq_alive/redis/base.rb
203
+ - lib/sidekiq_alive/redis/client.rb
204
+ - lib/sidekiq_alive/redis/client_adapter.rb
157
205
  - lib/sidekiq_alive/server.rb
158
206
  - lib/sidekiq_alive/version.rb
159
207
  - lib/sidekiq_alive/worker.rb
160
- - sidekiq_alive.gemspec
161
208
  homepage: https://github.com/arturictus/sidekiq_alive
162
209
  licenses:
163
210
  - MIT
164
- metadata: {}
165
- post_install_message:
211
+ metadata:
212
+ homepage_uri: https://github.com/arturictus/sidekiq_alive
213
+ source_code_uri: https://github.com/arturictus/sidekiq_alive
214
+ changelog_uri: https://github.com/arturictus/sidekiq_alive/releases
215
+ documentation_uri: https://github.com/arturictus/sidekiq_alive/blob/v2.1.8/README.md
216
+ bug_tracker_uri: https://github.com/arturictus/sidekiq_alive/issues
217
+ post_install_message:
166
218
  rdoc_options: []
167
219
  require_paths:
168
220
  - lib
@@ -170,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
222
  requirements:
171
223
  - - ">="
172
224
  - !ruby/object:Gem::Version
173
- version: '0'
225
+ version: 2.7.0
174
226
  required_rubygems_version: !ruby/object:Gem::Requirement
175
227
  requirements:
176
228
  - - ">="
@@ -178,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
230
  version: '0'
179
231
  requirements: []
180
232
  rubygems_version: 3.3.26
181
- signing_key:
233
+ signing_key:
182
234
  specification_version: 4
183
235
  summary: Liveness probe for sidekiq on Kubernetes deployments.
184
236
  test_files: []
@@ -1,41 +0,0 @@
1
- name: Ruby CI
2
-
3
- on:
4
- push:
5
- branches: [main, master]
6
- pull_request:
7
- branches: [main, master]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- ruby-version: ["3.1", "3.0", "2.7", "2.6", "2.5"]
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@v1
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/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
- vendor
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.1.3
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at arturictus@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in sidekiq_alive.gemspec
6
- gemspec
7
-
8
- gem 'pry'
data/Gemfile.lock DELETED
@@ -1,60 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sidekiq_alive (2.1.6)
5
- sidekiq
6
- webrick
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- coderay (1.1.2)
12
- connection_pool (2.2.5)
13
- diff-lcs (1.3)
14
- method_source (0.9.2)
15
- mock_redis (0.19.0)
16
- pry (0.12.2)
17
- coderay (~> 1.1.0)
18
- method_source (~> 0.9.0)
19
- rack (2.2.3)
20
- rack-test (1.1.0)
21
- rack (>= 1.0, < 3)
22
- rake (13.0.3)
23
- redis (4.6.0)
24
- rspec (3.8.0)
25
- rspec-core (~> 3.8.0)
26
- rspec-expectations (~> 3.8.0)
27
- rspec-mocks (~> 3.8.0)
28
- rspec-core (3.8.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-expectations (3.8.2)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-mocks (3.8.0)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.8.0)
36
- rspec-sidekiq (3.0.3)
37
- rspec-core (~> 3.0, >= 3.0.0)
38
- sidekiq (>= 2.4.0)
39
- rspec-support (3.8.0)
40
- sidekiq (6.4.1)
41
- connection_pool (>= 2.2.2)
42
- rack (~> 2.0)
43
- redis (>= 4.2.0)
44
- webrick (1.7.0)
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
50
- bundler (> 1.16)
51
- mock_redis
52
- pry
53
- rack-test
54
- rake (~> 13.0)
55
- rspec (~> 3.0)
56
- rspec-sidekiq (~> 3.0)
57
- sidekiq_alive!
58
-
59
- BUNDLED WITH
60
- 2.2.22
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 Artur Pañach
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'sidekiq_alive'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/docker-compose.yml DELETED
@@ -1,6 +0,0 @@
1
- version: '3.6'
2
- services:
3
- redis:
4
- image: redis
5
- ports:
6
- - 6379:6379
@@ -1,40 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'sidekiq_alive/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'sidekiq_alive'
7
- spec.version = SidekiqAlive::VERSION
8
- spec.authors = ['Artur Pañach']
9
- spec.email = ['arturictus@gmail.com']
10
-
11
- spec.summary = 'Liveness probe for sidekiq on Kubernetes deployments.'
12
- spec.description = 'SidekiqAlive offers a solution to add liveness probe of a Sidekiq instance.
13
-
14
- How?
15
-
16
- 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.
17
-
18
- A Sidekiq job is the responsable to storing this key. If Sidekiq stops processing jobs
19
- this key gets expired by Redis an consequently the http server will return a 500 error.
20
-
21
- This Job is responsible to requeue itself for the next liveness probe.'
22
- spec.homepage = 'https://github.com/arturictus/sidekiq_alive'
23
- spec.license = 'MIT'
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
28
- spec.bindir = 'exe'
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ['lib']
31
-
32
- spec.add_development_dependency 'bundler', '> 1.16'
33
- spec.add_development_dependency 'mock_redis'
34
- spec.add_development_dependency 'rack-test'
35
- spec.add_development_dependency 'rake', '~> 13.0'
36
- spec.add_development_dependency 'rspec', '~> 3.0'
37
- spec.add_development_dependency 'rspec-sidekiq', '~> 3.0'
38
- spec.add_dependency 'sidekiq'
39
- spec.add_dependency 'webrick'
40
- end