sidekiq_alive 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +33 -38
- data/lib/sidekiq_alive.rb +16 -13
- data/lib/sidekiq_alive/config.rb +2 -4
- data/lib/sidekiq_alive/version.rb +1 -1
- data/lib/sidekiq_alive/worker.rb +4 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 364bf320e50acf4acacc6b092ddc878e094762a048f03b8496b03dca50c79c67
|
4
|
+
data.tar.gz: a19db126856fbb3629994f2d0aec3fd839462c204a62abe03e0833f140fb16f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23f150276af1a182dc6dd7eef752125f12c65de9479ca9877294e0344dd02c9b49cd4174ebbb593996ab8937d538ef5a9b446eed19d5667b6462335d97e5e3a
|
7
|
+
data.tar.gz: 251ddc155702aa38adcd7368f5dd7e55c9fc40558a2e90fcd05d8641e78faa40337060deef492c23e602884250c6e66dfed1a77c46e058149658975e1e858543
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,23 @@ This worker is responsible to requeue itself for the next liveness probe.
|
|
18
18
|
|
19
19
|
Each instance in kubernetes will be checked based on `ENV` variable `HOSTNAME` (kubernetes sets this for each replica/pod).
|
20
20
|
|
21
|
+
On initialization SidekiqAlive will asign to Sidekiq::Worker a queue with the current host and add this queue to the current instance queues to process.
|
22
|
+
|
23
|
+
example:
|
24
|
+
|
25
|
+
```
|
26
|
+
hostname: foo
|
27
|
+
Worker queue: sidekiq_alive-foo
|
28
|
+
instance queues:
|
29
|
+
- sidekiq_alive-foo
|
30
|
+
*- your queues
|
31
|
+
|
32
|
+
hostname: bar
|
33
|
+
Worker queue: sidekiq_alive-bar
|
34
|
+
instance queues:
|
35
|
+
- sidekiq_alive-bar
|
36
|
+
*- your queues
|
37
|
+
```
|
21
38
|
|
22
39
|
## Installation
|
23
40
|
|
@@ -35,29 +52,21 @@ Or install it yourself as:
|
|
35
52
|
|
36
53
|
$ gem install sidekiq_alive
|
37
54
|
|
38
|
-
Run `Sidekiq` with a `sidekiq_alive` queue.
|
39
|
-
|
40
|
-
```
|
41
|
-
sidekiq -q sidekiq_alive
|
42
|
-
```
|
43
|
-
|
44
|
-
or in your config:
|
45
55
|
|
46
|
-
|
47
|
-
```yaml
|
48
|
-
queues:
|
49
|
-
- default
|
50
|
-
- sidekiq_alive
|
51
|
-
```
|
56
|
+
## Usage
|
52
57
|
|
53
|
-
|
58
|
+
SidekiqAlive will start when running `sidekiq` command.
|
54
59
|
|
55
|
-
|
56
|
-
Check [recommended kubernetes setup](#kubernetes-setup)
|
60
|
+
Run `Sidekiq`
|
57
61
|
|
58
|
-
|
62
|
+
```
|
63
|
+
bundle exec sidekiq
|
64
|
+
```
|
59
65
|
|
60
|
-
|
66
|
+
```
|
67
|
+
curl localhost:7433
|
68
|
+
#=> Alive!
|
69
|
+
```
|
61
70
|
|
62
71
|
|
63
72
|
__how to disable?__
|
@@ -156,28 +165,14 @@ SidekiqAlive.setup do |config|
|
|
156
165
|
# require 'net/http'
|
157
166
|
# config.callback = proc { Net::HTTP.get("https://status.com/ping") }
|
158
167
|
|
159
|
-
# ==>
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
# where sidekiq is processing SidekiqALive gets overloaded and takes
|
164
|
-
# longer than the `ttl` to process SidekiqAlive::Worker will make the liveness probe
|
165
|
-
# to fail. Sidekiq overloaded and restarting every `ttl` cicle.
|
166
|
-
# Add the sidekiq alive queue!!
|
168
|
+
# ==> Queue Prefix
|
169
|
+
# SidekiqAlive will run in a independent queue for each instance/replica
|
170
|
+
# This queue name will be generated with: "#{queue_prefix}-#{hostname}.
|
171
|
+
# You can customize the prefix here.
|
167
172
|
# default: :sidekiq_alive
|
168
173
|
#
|
169
|
-
# config.
|
170
|
-
|
171
|
-
# ==> delay_between_async_other_host_queue
|
172
|
-
# When instance receives a job from another instance it requeues itself again
|
173
|
-
# until the owner instance process it. This was causing a lot of read/writes in big deployments
|
174
|
-
# with a lot of replicas.
|
175
|
-
# Delaying the requeue proves to be less read/write intensive
|
176
|
-
# default: 1
|
177
|
-
#
|
178
|
-
# config.delay_between_async_other_host_queue = 0.5
|
179
|
-
# #or
|
180
|
-
# config.delay_between_async_other_host_queue = false
|
174
|
+
# config.queue_prefix = :other
|
175
|
+
|
181
176
|
end
|
182
177
|
```
|
183
178
|
|
data/lib/sidekiq_alive.rb
CHANGED
@@ -6,10 +6,12 @@ require 'sidekiq_alive/config'
|
|
6
6
|
|
7
7
|
module SidekiqAlive
|
8
8
|
def self.start
|
9
|
-
|
10
|
-
|
9
|
+
SidekiqAlive::Worker.sidekiq_options queue: current_queue
|
10
|
+
Sidekiq.configure_server do |sq_config|
|
11
11
|
|
12
|
-
|
12
|
+
sq_config.options[:queues] << current_queue
|
13
|
+
|
14
|
+
sq_config.on(:startup) do
|
13
15
|
SidekiqAlive.tap do |sa|
|
14
16
|
sa.logger.info(banner)
|
15
17
|
sa.register_current_instance
|
@@ -22,10 +24,10 @@ module SidekiqAlive
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
|
27
|
+
sq_config.on(:quiet) do
|
26
28
|
SidekiqAlive.unregister_current_instance
|
27
29
|
end
|
28
|
-
|
30
|
+
sq_config.on(:shutdown) do
|
29
31
|
Process.kill('TERM', @server_pid) unless @server_pid.nil?
|
30
32
|
Process.wait(@server_pid) unless @server_pid.nil?
|
31
33
|
SidekiqAlive.unregister_current_instance
|
@@ -33,12 +35,8 @@ module SidekiqAlive
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def self.
|
37
|
-
|
38
|
-
config.preferred_queue.to_sym
|
39
|
-
else
|
40
|
-
queues.first
|
41
|
-
end
|
38
|
+
def self.current_queue
|
39
|
+
"#{config.queue_prefix}-#{hostname}"
|
42
40
|
end
|
43
41
|
|
44
42
|
def self.register_current_instance
|
@@ -57,10 +55,15 @@ module SidekiqAlive
|
|
57
55
|
end
|
58
56
|
|
59
57
|
def self.purge_pending_jobs
|
58
|
+
# TODO:
|
59
|
+
# Sidekiq 6 allows better way to find scheduled jobs:
|
60
|
+
# https://github.com/mperham/sidekiq/wiki/API#scan
|
60
61
|
scheduled_set = Sidekiq::ScheduledSet.new
|
61
|
-
jobs = scheduled_set.select { |job| job.klass == 'SidekiqAlive::Worker' && job.
|
62
|
-
logger.info("Purging #{jobs.count} pending for #{hostname}")
|
62
|
+
jobs = scheduled_set.select { |job| job.klass == 'SidekiqAlive::Worker' && job.queue == current_queue }
|
63
|
+
logger.info("[SidekiqAlive] Purging #{jobs.count} pending for #{hostname}")
|
63
64
|
jobs.each(&:delete)
|
65
|
+
logger.info("[SidekiqAlive] Removing queue #{current_queue}")
|
66
|
+
Sidekiq::Queue.new(current_queue).clear
|
64
67
|
end
|
65
68
|
|
66
69
|
def self.current_instance_register_key
|
data/lib/sidekiq_alive/config.rb
CHANGED
@@ -7,8 +7,7 @@ module SidekiqAlive
|
|
7
7
|
:time_to_live,
|
8
8
|
:callback,
|
9
9
|
:registered_instance_key,
|
10
|
-
:
|
11
|
-
:delay_between_async_other_host_queue
|
10
|
+
:queue_prefix
|
12
11
|
|
13
12
|
def initialize
|
14
13
|
set_defaults
|
@@ -20,8 +19,7 @@ module SidekiqAlive
|
|
20
19
|
@time_to_live = 10 * 60
|
21
20
|
@callback = proc {}
|
22
21
|
@registered_instance_key = 'SIDEKIQ_REGISTERED_INSTANCE'
|
23
|
-
@
|
24
|
-
@delay_between_async_other_host_queue = 1
|
22
|
+
@queue_prefix = :sidekiq_alive
|
25
23
|
end
|
26
24
|
|
27
25
|
def registration_ttl
|
data/lib/sidekiq_alive/worker.rb
CHANGED
@@ -4,19 +4,9 @@ module SidekiqAlive
|
|
4
4
|
sidekiq_options retry: false
|
5
5
|
|
6
6
|
def perform(hostname = SidekiqAlive.hostname)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# schedule next living probe
|
11
|
-
self.class.perform_in(config.time_to_live / 2, current_hostname)
|
12
|
-
else
|
13
|
-
# requeue for hostname to validate it's own liveness probe
|
14
|
-
if config.delay_between_async_other_host_queue
|
15
|
-
self.class.perform_in(config.delay_between_async_other_host_queue, hostname)
|
16
|
-
else
|
17
|
-
self.class.perform_async(hostname)
|
18
|
-
end
|
19
|
-
end
|
7
|
+
write_living_probe
|
8
|
+
# schedule next living probe
|
9
|
+
self.class.perform_in(config.time_to_live / 2, current_hostname)
|
20
10
|
end
|
21
11
|
|
22
12
|
def hostname_registered?(hostname)
|
@@ -31,7 +21,7 @@ module SidekiqAlive
|
|
31
21
|
# Increment ttl for current registered instance
|
32
22
|
SidekiqAlive.register_current_instance
|
33
23
|
# after callbacks
|
34
|
-
config.callback.call()
|
24
|
+
config.callback.call() rescue nil
|
35
25
|
end
|
36
26
|
|
37
27
|
def current_hostname
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_alive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
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: 2019-09-
|
11
|
+
date: 2019-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|