resqued 0.12.0 → 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: 5a92bd03c3a0bf63c872341d0df842ea52762a641efeb490584ef508ff61a868
4
- data.tar.gz: 0c49b197b2fc672ff436f3eab41908de2a2a6e641a9a2d7df202a14c90557263
3
+ metadata.gz: 87a69574c5ec392def740d29a5274248e815e96f02304f59e27c0faa805153a4
4
+ data.tar.gz: 6809178bc9ad88a6c8da0be070521aa9273ecf4eac6b99e5219d0870af813efe
5
5
  SHA512:
6
- metadata.gz: cebc5d49661bafd589c3eeecea7a2e8729fe26a546c6b2dd3839c8b7939c62f2baf7f26b99434df8863759a7bb228f5939551f1986e9798aab0e9ff314337d69
7
- data.tar.gz: e3fdac521d55d512431f24d3dc26fdbd435491d7251ab6c5f4e7f375fac9d1956e2e878dcad47b54c1fe2323a968222dced0fd81733163c29eb61819cdc8f68d
6
+ metadata.gz: 94c143e2563fe9b42f6e3e73361b0a0949219e690188b822aa91da8247bef42f3e223844a9f7348fe03cc340a1b6fd70c6ef802bca8413d07d6c1eb4eb398ad7
7
+ data.tar.gz: 01acb7c8e6a9036696e53a4c97e09b78c812ab8cb0211e686ba79391cbab1663d54979c91e2405f8bb42c980534abb2505e459a5fd7d81aa8cd581c53cf8db4b
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
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
+
7
+ v0.12.1
8
+ -------
9
+ * Fixed Resqued::TestCase. v0.12.0 introduced a regression that stopped
10
+ `after_fork` blocks from being tested. This fixes some other problems in CI,
11
+ too. (#66)
12
+
3
13
  v0.12.0
4
14
  -------
5
15
  * Drop "resque" as a dependency. Apps that use Resqued with a different job
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"
@@ -96,7 +96,7 @@ module Resqued
96
96
  if Resque.respond_to?("logger=")
97
97
  Resque.logger = Resqued::Logging.build_logger
98
98
  end
99
- rescue LoadError
99
+ rescue LoadError # rubocop: disable Lint/SuppressedException
100
100
  # Skip this step.
101
101
  end
102
102
 
@@ -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
@@ -17,11 +17,17 @@ module Resqued
17
17
  config = Resqued::Config.new(paths)
18
18
  config.before_fork(RuntimeInfo.new)
19
19
  config.build_workers
20
+ config.after_fork(FakeWorker.new)
20
21
  end
21
22
  end
22
23
 
23
24
  Default = LoadConfig
24
25
 
25
26
  include Default
27
+
28
+ class FakeWorker
29
+ def initialize
30
+ end
31
+ end
26
32
  end
27
33
  end
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = "0.12.0".freeze
2
+ VERSION = "0.12.2".freeze
3
3
  end
@@ -1,3 +1,4 @@
1
1
  before_fork do
2
+ require "resque"
2
3
  Resque.redis = Redis.new(host: "localhost", port: ENV["RESQUED_TEST_REDIS_PORT"].to_i)
3
4
  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.0
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Burke
8
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
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: resque
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.9.1
47
+ version: 13.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.9.1
54
+ version: 13.0.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: resque
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 13.0.1
61
+ version: 1.9.1
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: 13.0.1
68
+ version: 1.9.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.78.0
89
+ version: 0.79.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.78.0
96
+ version: 0.79.0
97
97
  description: Daemon of resque workers
98
98
  email: spraints@gmail.com
99
99
  executables:
@@ -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
@@ -178,6 +180,7 @@ summary: Daemon of resque workers
178
180
  test_files:
179
181
  - spec/spec_helper.rb
180
182
  - spec/integration/restart_spec.rb
183
+ - spec/integration/quit_and_wait_spec.rb
181
184
  - spec/integration/listener_still_starting_spec.rb
182
185
  - spec/integration/master_inherits_child_spec.rb
183
186
  - spec/support/resqued_integration_helpers.rb