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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87a69574c5ec392def740d29a5274248e815e96f02304f59e27c0faa805153a4
4
- data.tar.gz: 6809178bc9ad88a6c8da0be070521aa9273ecf4eac6b99e5219d0870af813efe
3
+ metadata.gz: a05ff83ea7efb498899c8e366977f9b59e854c5c999ae9b8edcdb66e36ec8551
4
+ data.tar.gz: af4beac8bbd7b030527dc23b60587672126227a022560962f4d31f62efef5d5d
5
5
  SHA512:
6
- metadata.gz: 94c143e2563fe9b42f6e3e73361b0a0949219e690188b822aa91da8247bef42f3e223844a9f7348fe03cc340a1b6fd70c6ef802bca8413d07d6c1eb4eb398ad7
7
- data.tar.gz: 01acb7c8e6a9036696e53a4c97e09b78c812ab8cb0211e686ba79391cbab1663d54979c91e2405f8bb42c980534abb2505e459a5fd7d81aa8cd581c53cf8db4b
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
@@ -12,6 +12,10 @@ module Resqued
12
12
  def after_fork(&block)
13
13
  end
14
14
 
15
+ # Public: Define a block to be run once after each worker exits.
16
+ def after_exit(&block)
17
+ end
18
+
15
19
  # Public: Define a worker that will work on a queue.
16
20
  def worker(*queues)
17
21
  end
@@ -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)
@@ -18,6 +18,7 @@ module Resqued
18
18
  config.before_fork(RuntimeInfo.new)
19
19
  config.build_workers
20
20
  config.after_fork(FakeWorker.new)
21
+ config.after_exit(Resqued::WorkerSummary.new(alive_time_sec: 1.0, process_status: Process::Status.allocate))
21
22
  end
22
23
  end
23
24
 
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = "0.12.2".freeze
2
+ VERSION = "0.12.3".freeze
3
3
  end
@@ -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,5 @@
1
+ after_exit do
2
+ raise "boom"
3
+ end
4
+
5
+ worker "test"
@@ -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.2
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-10-19 00:00:00.000000000 Z
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