resqued 0.12.1 → 0.12.2

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: 13f45787a92226688e4b30d34f1f6a5390277c34423b94786511d6bf6a4b5d71
4
- data.tar.gz: 0d6af78fd2ced8e9fff8703456052333ddb20e75c32d7c1ffab0466dbab6b9cb
3
+ metadata.gz: 87a69574c5ec392def740d29a5274248e815e96f02304f59e27c0faa805153a4
4
+ data.tar.gz: 6809178bc9ad88a6c8da0be070521aa9273ecf4eac6b99e5219d0870af813efe
5
5
  SHA512:
6
- metadata.gz: 782cb7f9c4d7ceeb3e7de4d8612eb2df0363105f447fe110404dc779e73cffa9a433e3d08f6021cd6fd6f7f17b34c305c4ac623c28536b140c72ca8a451f3030
7
- data.tar.gz: 766db53a09ffab45db9288b9ed165bdb0c679ff394edcb2f40dd1e626c12e1735cb32a4dc39e2fbbb248d8d596826ff1bb01ff568bd944ad9ff0483c836947d4
6
+ metadata.gz: 94c143e2563fe9b42f6e3e73361b0a0949219e690188b822aa91da8247bef42f3e223844a9f7348fe03cc340a1b6fd70c6ef802bca8413d07d6c1eb4eb398ad7
7
+ data.tar.gz: 01acb7c8e6a9036696e53a4c97e09b78c812ab8cb0211e686ba79391cbab1663d54979c91e2405f8bb42c980534abb2505e459a5fd7d81aa8cd581c53cf8db4b
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Starting with version 0.6.1, resqued uses semantic versioning to indicate incompatibilities between the master process, listener process, and configuration.
2
2
 
3
+ v0.12.2
4
+ -------
5
+ * Added lifecycle hook for container runtimes. (#67)
6
+
3
7
  v0.12.1
4
8
  -------
5
9
  * Fixed Resqued::TestCase. v0.12.0 introduced a regression that stopped
data/exe/resqued CHANGED
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if ARGV[0] == "listener"
3
+ case ARGV[0]
4
+ when "listener"
4
5
  require "resqued/listener"
5
6
  Resqued::Listener.exec!
6
7
  exit 0
8
+ when "quit-and-wait"
9
+ require "resqued/quit-and-wait"
10
+ Resqued::QuitAndWait.exec!(ARGV.drop(1))
11
+ exit 0
7
12
  end
8
13
 
9
14
  require "optparse"
@@ -0,0 +1,84 @@
1
+ require "optparse"
2
+
3
+ module Resqued
4
+ class QuitAndWait
5
+ def self.exec!(argv)
6
+ options = { grace_seconds: 30 }
7
+
8
+ opts = OptionParser.new do |opts| # rubocop: disable Lint/ShadowingOuterLocalVariable
9
+ opts.banner = <<~USAGE
10
+ Usage: resqued quit-and-wait PIDFILE [--grace-period SECONDS]
11
+
12
+ Use this as a preStop script in kubernetes. This script will send a SIGQUIT to
13
+ resqued immediately, and then sleep until either resqued exits or until the
14
+ grace period is nearing expiration. This script exits 0 if resqued exited and
15
+ 99 otherwise.
16
+ USAGE
17
+
18
+ opts.on "-h", "--help", "Show this message" do
19
+ puts opts
20
+ exit
21
+ end
22
+
23
+ opts.on "-v", "--version", "Show the version" do
24
+ require "resqued/version"
25
+ puts Resqued::VERSION
26
+ exit
27
+ end
28
+
29
+ opts.on "--grace-period SECONDS", Numeric, "Grace period provided to container runtime (default 30)" do |v|
30
+ options[:grace_seconds] = v
31
+ end
32
+
33
+ opts.on "--quiet" do
34
+ options[:quiet] = true
35
+ end
36
+ end
37
+
38
+ argv = opts.parse(argv)
39
+ if argv.size != 1
40
+ puts opts
41
+ exit 1
42
+ end
43
+ options[:pidfile] = argv.shift
44
+
45
+ new(**options).exec!
46
+ end
47
+
48
+ def initialize(grace_seconds:, pidfile:, quiet: false)
49
+ @grace_seconds = grace_seconds
50
+ @pidfile = pidfile
51
+ @quiet = quiet
52
+ end
53
+
54
+ attr_reader :grace_seconds, :pidfile, :quiet
55
+
56
+ def exec!
57
+ start = Time.now
58
+ stop_at = start + grace_seconds - 5
59
+ pid = File.read(pidfile).to_i
60
+
61
+ log "kill -QUIT #{pid} (resqued-master)"
62
+ Process.kill(:QUIT, pid)
63
+
64
+ while Time.now < stop_at
65
+ begin
66
+ # check if pid is still alive.
67
+ Process.kill(0, pid)
68
+ rescue Errno::ESRCH # no such process, it exited!
69
+ log "ok: resqued-master with pid #{pid} exited"
70
+ exit 0
71
+ end
72
+ end
73
+
74
+ log "giving up, resqued-master with pid #{pid} is still running."
75
+ exit 99
76
+ end
77
+
78
+ def log(message)
79
+ return if quiet
80
+
81
+ puts "#{Time.now.strftime('%H:%M:%S.%L')} #{message}"
82
+ end
83
+ end
84
+ end
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = "0.12.1".freeze
2
+ VERSION = "0.12.2".freeze
3
3
  end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require "timeout"
3
+
4
+ describe "quit-and-wait gracefully stops resqued" do
5
+ include ResquedIntegrationHelpers
6
+
7
+ it do
8
+ pidfile = File.join(SPEC_TEMPDIR, "graceful.pid")
9
+
10
+ start_resqued(pidfile: pidfile)
11
+ expect_running listener: "listener #1"
12
+
13
+ # Make sure the process gets cleaned up.
14
+ Thread.new do
15
+ begin
16
+ loop do
17
+ Process.wait(@pid)
18
+ end
19
+ rescue Errno::ECHILD
20
+ # ok!
21
+ end
22
+ end
23
+
24
+ Timeout.timeout(15) do
25
+ expect(system(resqued_path, "quit-and-wait", pidfile, "--grace-period", "10")).to be true
26
+ end
27
+
28
+ expect_not_running
29
+ end
30
+
31
+ after do
32
+ begin
33
+ Process.kill(:QUIT, @pid) if @pid
34
+ rescue Errno::ESRCH
35
+ end
36
+ end
37
+ end
@@ -1,20 +1,25 @@
1
1
  module ResquedIntegrationHelpers
2
2
  include ResquedPath
3
3
 
4
- def start_resqued(config: "", debug: false)
5
- # Don't configure any workers. That way, we don't need to have redis running.
4
+ def start_resqued(config: "", debug: false, pidfile: nil)
5
+ # Don't configure any workers by default. That way, we don't need to have
6
+ # redis running.
6
7
  config_path = File.join(SPEC_TEMPDIR, "config.rb")
7
8
  File.write(config_path, config)
8
9
 
9
- @pid =
10
- if debug
11
- spawn resqued_path, config_path
12
- else
13
- logfile = File.join(SPEC_TEMPDIR, "resqued.log")
14
- File.write(logfile, "") # truncate it
10
+ cmd = [resqued_path]
11
+ if pidfile
12
+ cmd += ["--pidfile", pidfile]
13
+ end
14
+ unless debug
15
+ logfile = File.join(SPEC_TEMPDIR, "resqued.log")
16
+ File.write(logfile, "") # truncate it
17
+ cmd += ["--logfile", logfile]
18
+ end
19
+ cmd += [config_path]
20
+
21
+ @pid = spawn(*cmd)
15
22
 
16
- spawn resqued_path, "--logfile", logfile, config_path
17
- end
18
23
  sleep 1.0
19
24
  end
20
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resqued
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Burke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-23 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio
@@ -127,6 +127,7 @@ files:
127
127
  - lib/resqued/master_state.rb
128
128
  - lib/resqued/pidfile.rb
129
129
  - lib/resqued/procline_version.rb
130
+ - lib/resqued/quit-and-wait.rb
130
131
  - lib/resqued/runtime_info.rb
131
132
  - lib/resqued/sleepy.rb
132
133
  - lib/resqued/test_case.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/fixtures/test_case_no_workers.rb
140
141
  - spec/integration/listener_still_starting_spec.rb
141
142
  - spec/integration/master_inherits_child_spec.rb
143
+ - spec/integration/quit_and_wait_spec.rb
142
144
  - spec/integration/restart_spec.rb
143
145
  - spec/resqued/backoff_spec.rb
144
146
  - spec/resqued/config/fork_event_spec.rb
@@ -156,7 +158,7 @@ homepage: https://github.com/spraints/resqued
156
158
  licenses:
157
159
  - MIT
158
160
  metadata: {}
159
- post_install_message:
161
+ post_install_message:
160
162
  rdoc_options: []
161
163
  require_paths:
162
164
  - lib
@@ -171,28 +173,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  - !ruby/object:Gem::Version
172
174
  version: '0'
173
175
  requirements: []
174
- rubygems_version: 3.2.15
175
- signing_key:
176
+ rubygems_version: 3.1.6
177
+ signing_key:
176
178
  specification_version: 4
177
179
  summary: Daemon of resque workers
178
180
  test_files:
179
- - spec/fixtures/test_case_after_fork_raises.rb
180
- - spec/fixtures/test_case_before_fork_raises.rb
181
+ - spec/spec_helper.rb
182
+ - spec/integration/restart_spec.rb
183
+ - spec/integration/quit_and_wait_spec.rb
184
+ - spec/integration/listener_still_starting_spec.rb
185
+ - spec/integration/master_inherits_child_spec.rb
186
+ - spec/support/resqued_integration_helpers.rb
187
+ - spec/support/custom_matchers.rb
188
+ - spec/support/resqued_path.rb
189
+ - spec/support/extra-child-shim
181
190
  - spec/fixtures/test_case_clean.rb
191
+ - spec/fixtures/test_case_before_fork_raises.rb
182
192
  - spec/fixtures/test_case_environment.rb
183
193
  - spec/fixtures/test_case_no_workers.rb
184
- - spec/integration/listener_still_starting_spec.rb
185
- - spec/integration/master_inherits_child_spec.rb
186
- - spec/integration/restart_spec.rb
187
- - spec/resqued/backoff_spec.rb
194
+ - spec/fixtures/test_case_after_fork_raises.rb
195
+ - spec/resqued/config_spec.rb
188
196
  - spec/resqued/config/fork_event_spec.rb
189
197
  - spec/resqued/config/worker_spec.rb
190
- - spec/resqued/config_spec.rb
191
198
  - spec/resqued/sleepy_spec.rb
192
- - spec/resqued/start_ctx_spec.rb
193
199
  - spec/resqued/test_case_spec.rb
194
- - spec/spec_helper.rb
195
- - spec/support/custom_matchers.rb
196
- - spec/support/extra-child-shim
197
- - spec/support/resqued_integration_helpers.rb
198
- - spec/support/resqued_path.rb
200
+ - spec/resqued/start_ctx_spec.rb
201
+ - spec/resqued/backoff_spec.rb