sidekiq-worker-killer 1.0.1 → 1.1.0

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: f8573256c162630662fbb9be660375da63c3c8cbe3fb11d9851e36b1c0456eff
4
- data.tar.gz: 63a6bea822d499f22f283f704f80e0954ac006ed442f6cb7632fa204602051f3
3
+ metadata.gz: 1335f7577f6a507808c59651cc9f479a49a9d54e144906b39b06355af0fcfcba
4
+ data.tar.gz: f61243439575d5ec2f75e0e7e803ff6588279b349a4ab9ebabc62e58fb3fcb7e
5
5
  SHA512:
6
- metadata.gz: c1fe7ab3d39860cbd742af569a3e5b3a37173bbdffa751ebc76aae1cbf67d09a5745991e8ad9c5b50671705b110abeab3ee4124e69c3ebbccc658579409cbd6d
7
- data.tar.gz: f65acd7d78a86152a2d04cd5c4ef0046885366540c362fe0a8c61caa4f1d04d4263f338bd9769c00ea09530151b9a8da48f34cf71377ecfec6517c4c36075d80
6
+ metadata.gz: 97742129013c4374090ed58f35d9b407f6dc2b9ff44a23d4de187b7d3035c11961ebb089b0753bf7b1688d386d77b2aef7cceba4344dd614a2dd3181fc28a0c2
7
+ data.tar.gz: cbf8b55a9bbf3171f988c0eabb4a137bbe3e458f9aa8368cb2c1cbe3759a14ce4b6dd919b9568458e48ac473c7780f01ad72be437503ee8e3695e1b67613f59d
data/README.md CHANGED
@@ -52,6 +52,7 @@ The following options can be overridden.
52
52
  | kill_signal | SIGKILL | Signal to use to kill Sidekiq process if it doesn't stop. |
53
53
  | gc | true | Try to run garbage collection before Sidekiq process stops in case of exceeded max_rss. |
54
54
  | skip_shutdown_if | proc {false} | Executes a block of code after max_rss exceeds but before requesting shutdown. |
55
+ | on_shutdown | nil | Executes a block of code before just before requesting shutdown. This can be used to send custom logs or metrics to external services. |
55
56
 
56
57
  *skip_shutdown_if* is expected to return anything other than `false` or `nil` to skip shutdown.
57
58
 
@@ -1,7 +1,7 @@
1
1
  # rubocop:disable Style/ClassAndModuleChildren
2
2
  module Sidekiq
3
3
  class WorkerKiller
4
- VERSION = "1.0.1".freeze
4
+ VERSION = "1.1.0".freeze
5
5
  end
6
6
  end
7
7
  # rubocop:enable Style/ClassAndModuleChildren
@@ -36,6 +36,9 @@ class Sidekiq::WorkerKiller
36
36
  # @option options [Proc] skip_shutdown_if
37
37
  # Executes a block of code after max_rss exceeds but before requesting
38
38
  # shutdown. (default: `proc {false}`)
39
+ # @option options [Proc] on_shutdown
40
+ # Executes a block of code right before a shutdown happens.
41
+ # (default: `nil`)
39
42
  def initialize(options = {})
40
43
  @max_rss = options.fetch(:max_rss, 0)
41
44
  @grace_time = options.fetch(:grace_time, 15 * 60)
@@ -43,6 +46,7 @@ class Sidekiq::WorkerKiller
43
46
  @kill_signal = options.fetch(:kill_signal, "SIGKILL")
44
47
  @gc = options.fetch(:gc, true)
45
48
  @skip_shutdown = options.fetch(:skip_shutdown_if, proc { false })
49
+ @on_shutdown = options.fetch(:on_shutdown, nil)
46
50
  end
47
51
 
48
52
  # @param [String, Class] worker_class
@@ -68,17 +72,23 @@ class Sidekiq::WorkerKiller
68
72
 
69
73
  warn "current RSS #{current_rss} of #{identity} exceeds " \
70
74
  "maximum RSS #{@max_rss}"
75
+
76
+ run_shutdown_hook(worker, job, queue)
71
77
  request_shutdown
72
78
  end
73
79
 
74
80
  private
75
81
 
82
+ def run_shutdown_hook(worker, job, queue)
83
+ @on_shutdown.respond_to?(:call) && @on_shutdown.call(worker, job, queue)
84
+ end
85
+
76
86
  def skip_shutdown?(worker, job, queue)
77
87
  @skip_shutdown.respond_to?(:call) && @skip_shutdown.call(worker, job, queue)
78
88
  end
79
89
 
80
90
  def request_shutdown
81
- # In another thread to allow undelying job to finish
91
+ # In another thread to allow underlying job to finish
82
92
  Thread.new do
83
93
  # Only if another thread is not already
84
94
  # shutting down the Sidekiq process
@@ -129,6 +129,28 @@ describe Sidekiq::WorkerKiller do
129
129
  end
130
130
  end
131
131
 
132
+ context "and on_shutdown is given" do
133
+ subject{ described_class.new(max_rss: 2, on_shutdown: on_shutdown_proc) }
134
+
135
+ context "and on_shutdown is a proc" do
136
+ let(:on_shutdown_proc) { proc { |worker, job, queue| nil } }
137
+ it "should execute on_shutdown hook" do
138
+ expect(subject).to receive(:request_shutdown).once
139
+ expect(on_shutdown_proc).to receive(:call).once
140
+ subject.call(worker, job, queue){}
141
+ end
142
+ end
143
+
144
+ context "and on_shutdown is a lambda" do
145
+ let(:on_shutdown_proc) { ->(worker, job, queue) { nil } }
146
+ it "should execute on_shutdown hook" do
147
+ expect(subject).to receive(:request_shutdown).once
148
+ expect(on_shutdown_proc).to receive(:call).once
149
+ subject.call(worker, job, queue){}
150
+ end
151
+ end
152
+ end
153
+
132
154
  context "when gc is false" do
133
155
  subject{ described_class.new(max_rss: 2, gc: false) }
134
156
  it "should not call garbage collect" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-worker-killer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyrille Courtiere
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-02 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: get_process_mem
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - dev@klaxit.com
86
86
  executables: []
@@ -95,7 +95,7 @@ files:
95
95
  homepage: http://github.com/klaxit/sidekiq-worker-killer
96
96
  licenses: []
97
97
  metadata: {}
98
- post_install_message:
98
+ post_install_message:
99
99
  rdoc_options: []
100
100
  require_paths:
101
101
  - lib
@@ -110,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.0.3
114
- signing_key:
113
+ rubygems_version: 3.3.26
114
+ signing_key:
115
115
  specification_version: 4
116
116
  summary: Sidekiq worker killer
117
117
  test_files: