resqued 0.12.2 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +5 -0
- data/lib/resqued/config/after_exit.rb +22 -0
- data/lib/resqued/config/dsl.rb +4 -0
- data/lib/resqued/config.rb +6 -0
- data/lib/resqued/test_case.rb +1 -0
- data/lib/resqued/version.rb +1 -1
- data/lib/resqued/worker.rb +15 -0
- data/spec/fixtures/test_case_after_exit_raises.rb +5 -0
- data/spec/resqued/config/exit_event_spec.rb +47 -0
- data/spec/resqued/test_case_spec.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a05ff83ea7efb498899c8e366977f9b59e854c5c999ae9b8edcdb66e36ec8551
|
4
|
+
data.tar.gz: af4beac8bbd7b030527dc23b60587672126227a022560962f4d31f62efef5d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55b640e571730cdaa8155c8296c21923eb54d9cb4fe93ec5245ee739e78201ff45736653544c070c0c6d012a0d83678d1158fe0243b1cf665d7292c29af10de6
|
7
|
+
data.tar.gz: b086650c78f7710ec143ac6e787a2cfd7809bae17c10fc9583259a37ae258ef65df3252052d6c5d35309e5c2ae15a90180fa856803bae40f356c277f6628d3fb
|
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.3
|
4
|
+
-------
|
5
|
+
* Add `after_exit` that provides a `WorkerSummary` about each exited worker.
|
6
|
+
|
3
7
|
v0.12.2
|
4
8
|
-------
|
5
9
|
* Added lifecycle hook for container runtimes. (#67)
|
data/README.md
CHANGED
@@ -152,6 +152,11 @@ You can configure the Resque worker in the `after_fork` block
|
|
152
152
|
worker.term_timeout = 1.minute
|
153
153
|
end
|
154
154
|
|
155
|
+
after_exit do |worker_summary|
|
156
|
+
puts "Worker was alive for #{worker_summary.alive_time_sec}"
|
157
|
+
puts "Process::Status of exited worker: #{worker_summary.process_status.inspect}"
|
158
|
+
end
|
159
|
+
|
155
160
|
In this example, a Rails application is being set up with 7 workers:
|
156
161
|
* high
|
157
162
|
* low (interval = 30)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "resqued/config/base"
|
2
|
+
|
3
|
+
module Resqued
|
4
|
+
module Config
|
5
|
+
# A config handler that executes the `after_exit` block.
|
6
|
+
#
|
7
|
+
# after_exit do |worker_summary|
|
8
|
+
# # Runs in each listener.
|
9
|
+
# end
|
10
|
+
class AfterExit < Base
|
11
|
+
# Public.
|
12
|
+
def initialize(options = {})
|
13
|
+
@worker_summary = options.fetch(:worker_summary)
|
14
|
+
end
|
15
|
+
|
16
|
+
# DSL: execute the `after_exit` block.
|
17
|
+
def after_exit
|
18
|
+
yield @worker_summary
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/resqued/config/dsl.rb
CHANGED
data/lib/resqued/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "resqued/config/after_fork"
|
2
2
|
require "resqued/config/before_fork"
|
3
|
+
require "resqued/config/after_exit"
|
3
4
|
require "resqued/config/worker"
|
4
5
|
|
5
6
|
module Resqued
|
@@ -27,6 +28,11 @@ module Resqued
|
|
27
28
|
Resqued::Config::AfterFork.new(worker: worker).apply_all(@config_data)
|
28
29
|
end
|
29
30
|
|
31
|
+
# Public: Perform the `after_exit` action from the config.
|
32
|
+
def after_exit(worker_summary)
|
33
|
+
Resqued::Config::AfterExit.new(worker_summary: worker_summary).apply_all(@config_data)
|
34
|
+
end
|
35
|
+
|
30
36
|
# Public: Builds the workers specified in the config.
|
31
37
|
def build_workers
|
32
38
|
Resqued::Config::Worker.new(config: self).apply_all(@config_data)
|
data/lib/resqued/test_case.rb
CHANGED
data/lib/resqued/version.rb
CHANGED
data/lib/resqued/worker.rb
CHANGED
@@ -64,6 +64,9 @@ module Resqued
|
|
64
64
|
@pid = nil
|
65
65
|
@backoff.died unless @killed
|
66
66
|
elsif !process_status.nil? && @self_started
|
67
|
+
alive_time_sec = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start_time
|
68
|
+
@config.after_exit(WorkerSummary.new(alive_time_sec: alive_time_sec, process_status: process_status))
|
69
|
+
|
67
70
|
log :debug, "#{summary} I exited: #{process_status}"
|
68
71
|
@pid = nil
|
69
72
|
@backoff.died unless @killed
|
@@ -84,6 +87,8 @@ module Resqued
|
|
84
87
|
@backoff.started
|
85
88
|
@self_started = true
|
86
89
|
@killed = false
|
90
|
+
@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
91
|
+
|
87
92
|
if @pid = fork
|
88
93
|
@pids << @pid
|
89
94
|
# still in the listener
|
@@ -112,4 +117,14 @@ module Resqued
|
|
112
117
|
log "Can't kill #{pid}: #{e}"
|
113
118
|
end
|
114
119
|
end
|
120
|
+
|
121
|
+
# Metadata for an exited listener worker.
|
122
|
+
class WorkerSummary
|
123
|
+
attr_reader :alive_time_sec, :process_status
|
124
|
+
|
125
|
+
def initialize(alive_time_sec:, process_status:)
|
126
|
+
@alive_time_sec = alive_time_sec
|
127
|
+
@process_status = process_status
|
128
|
+
end
|
129
|
+
end
|
115
130
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "resqued/worker"
|
3
|
+
require "resqued/config/after_exit"
|
4
|
+
|
5
|
+
describe do
|
6
|
+
before { evaluator.apply(config) }
|
7
|
+
|
8
|
+
context "after_exit" do
|
9
|
+
# Run the after_exit block.
|
10
|
+
#
|
11
|
+
# after_exit do |worker_summary|
|
12
|
+
# puts "#{worker_summary.alive_time_sec}"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# ignore calls to any other top-level method.
|
16
|
+
|
17
|
+
let(:config) { <<-END_CONFIG }
|
18
|
+
worker('one')
|
19
|
+
worker_pool(1)
|
20
|
+
queue('*')
|
21
|
+
|
22
|
+
after_exit do |worker_summary|
|
23
|
+
$after_exit_called = true
|
24
|
+
$worker_alive_time_sec = worker_summary.alive_time_sec
|
25
|
+
$exit_status = worker_summary.process_status.exitstatus
|
26
|
+
end
|
27
|
+
END_CONFIG
|
28
|
+
|
29
|
+
let(:evaluator) {
|
30
|
+
# In ruby versions < 3, Process::Status evaluates $? regardless of what status is returned by
|
31
|
+
# exitcode for a status created with Process::Status.allocate
|
32
|
+
fork do
|
33
|
+
exit!
|
34
|
+
end
|
35
|
+
_, status = Process.waitpid2
|
36
|
+
Resqued::Config::AfterExit.new(worker_summary: Resqued::WorkerSummary.new(alive_time_sec: 1, process_status: status))
|
37
|
+
}
|
38
|
+
|
39
|
+
it { expect($after_exit_called).to eq(true) }
|
40
|
+
it { expect($worker_alive_time_sec > 0).to eq(true) }
|
41
|
+
it { expect($exit_status).to eq(0) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class FakeResqueWorker
|
46
|
+
attr_accessor :token
|
47
|
+
end
|
@@ -9,6 +9,7 @@ describe Resqued::TestCase do
|
|
9
9
|
it { expect { test_case.assert_resqued "spec/fixtures/test_case_environment.rb", "spec/fixtures/test_case_clean.rb" }.not_to raise_error }
|
10
10
|
it { expect { test_case.assert_resqued "spec/fixtures/test_case_environment.rb", "spec/fixtures/test_case_before_fork_raises.rb" }.to raise_error(RuntimeError) }
|
11
11
|
it { expect { test_case.assert_resqued "spec/fixtures/test_case_environment.rb", "spec/fixtures/test_case_after_fork_raises.rb" }.to raise_error(RuntimeError) }
|
12
|
+
it { expect { test_case.assert_resqued "spec/fixtures/test_case_environment.rb", "spec/fixtures/test_case_after_exit_raises.rb" }.to raise_error(RuntimeError) }
|
12
13
|
it { expect { test_case.assert_resqued "spec/fixtures/test_case_environment.rb", "spec/fixtures/test_case_no_workers.rb" }.not_to raise_error }
|
13
14
|
end
|
14
15
|
end
|
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.
|
4
|
+
version: 0.12.3
|
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-
|
11
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kgio
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/resqued.rb
|
112
112
|
- lib/resqued/backoff.rb
|
113
113
|
- lib/resqued/config.rb
|
114
|
+
- lib/resqued/config/after_exit.rb
|
114
115
|
- lib/resqued/config/after_fork.rb
|
115
116
|
- lib/resqued/config/base.rb
|
116
117
|
- lib/resqued/config/before_fork.rb
|
@@ -133,6 +134,7 @@ files:
|
|
133
134
|
- lib/resqued/test_case.rb
|
134
135
|
- lib/resqued/version.rb
|
135
136
|
- lib/resqued/worker.rb
|
137
|
+
- spec/fixtures/test_case_after_exit_raises.rb
|
136
138
|
- spec/fixtures/test_case_after_fork_raises.rb
|
137
139
|
- spec/fixtures/test_case_before_fork_raises.rb
|
138
140
|
- spec/fixtures/test_case_clean.rb
|
@@ -143,6 +145,7 @@ files:
|
|
143
145
|
- spec/integration/quit_and_wait_spec.rb
|
144
146
|
- spec/integration/restart_spec.rb
|
145
147
|
- spec/resqued/backoff_spec.rb
|
148
|
+
- spec/resqued/config/exit_event_spec.rb
|
146
149
|
- spec/resqued/config/fork_event_spec.rb
|
147
150
|
- spec/resqued/config/worker_spec.rb
|
148
151
|
- spec/resqued/config_spec.rb
|
@@ -192,9 +195,11 @@ test_files:
|
|
192
195
|
- spec/fixtures/test_case_environment.rb
|
193
196
|
- spec/fixtures/test_case_no_workers.rb
|
194
197
|
- spec/fixtures/test_case_after_fork_raises.rb
|
198
|
+
- spec/fixtures/test_case_after_exit_raises.rb
|
195
199
|
- spec/resqued/config_spec.rb
|
196
200
|
- spec/resqued/config/fork_event_spec.rb
|
197
201
|
- spec/resqued/config/worker_spec.rb
|
202
|
+
- spec/resqued/config/exit_event_spec.rb
|
198
203
|
- spec/resqued/sleepy_spec.rb
|
199
204
|
- spec/resqued/test_case_spec.rb
|
200
205
|
- spec/resqued/start_ctx_spec.rb
|