good_job 3.18.0 → 3.18.1

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: cb40c03312f09c2cb91e77bce2ab3aacf87c62a18125d62b50bdc92b312d34f5
4
- data.tar.gz: c1c73c9264b8bd6454aad7685d326d082c00d5c3f14667ab89e1f77cce9059ea
3
+ metadata.gz: 2573770a9539b895705eee99e074ec34cc74a1b2fffc491c6b01fe2218792bf3
4
+ data.tar.gz: 49ae57e1ccfd0cf54421c349b1e0659dab195530f89ecce2bd6f29c37315e86d
5
5
  SHA512:
6
- metadata.gz: 9825b6d3c5a496c7fdee3aec3f0b5653a6c68d40b15487bb43d21b48817ae077052b3c3520b6ac0dd54354cc68b1157800270e95119240260ef68ab55046b293
7
- data.tar.gz: a903a5cac7a8b753e457d7e98018ca575825dcb1be515702cd30bd92494f3fc22740e09e48c4b3a8312fae2824021e86d6f6d9e431d0b10f39c05ea97457baca
6
+ metadata.gz: aa1cdc0760d2d139acd4f76d95aab2093480930dd04b1a93673510497abb0f5d589ff1d71741d4e6f940d0c983bb003cbadeb06d9702a7b1165ba0f45bb13a47
7
+ data.tar.gz: 7184e6f9816441a85d2d2574482fbb36ea39a3c0f76bb9a5169df9ee7ad63e7a5f150f110087eba9938bfc87af79745c4a9427391906a04457ed1993b7c2f6f2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.18.1](https://github.com/bensheldon/good_job/tree/v3.18.1) (2023-08-30)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.18.0...v3.18.1)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Respect the configured execution mode, even within the CLI [\#1056](https://github.com/bensheldon/good_job/pull/1056) ([bensheldon](https://github.com/bensheldon))
10
+
11
+ **Closed issues:**
12
+
13
+ - Bug: calling `GoodJob.restart` in Puma on\_worker\_boot starts GoodJob regardless of it being in async mode or not [\#1054](https://github.com/bensheldon/good_job/issues/1054)
14
+ - \[Feature Request?\] Config Option to Inline Child-Jobs in Worker Processes [\#1052](https://github.com/bensheldon/good_job/issues/1052)
15
+ - \[Feature Request\] Hook to extend cron schedules [\#1050](https://github.com/bensheldon/good_job/issues/1050)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - `GoodJob.restart` should not start capsules \(job execution\) when in a webserver but not in async mode [\#1055](https://github.com/bensheldon/good_job/pull/1055) ([bensheldon](https://github.com/bensheldon))
20
+
3
21
  ## [v3.18.0](https://github.com/bensheldon/good_job/tree/v3.18.0) (2023-08-30)
4
22
 
5
23
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.17.4...v3.18.0)
@@ -185,7 +185,7 @@ module GoodJob
185
185
  # @return [Boolean]
186
186
  def execute_async?
187
187
  execution_mode == :async_all ||
188
- (execution_mode.in?([:async, :async_server]) && in_server_process?)
188
+ (execution_mode.in?([:async, :async_server]) && GoodJob.configuration.in_webserver?)
189
189
  end
190
190
 
191
191
  # Whether in +:external+ execution mode.
@@ -193,7 +193,7 @@ module GoodJob
193
193
  def execute_externally?
194
194
  execution_mode.nil? ||
195
195
  execution_mode == :external ||
196
- (execution_mode.in?([:async, :async_server]) && !in_server_process?)
196
+ (execution_mode.in?([:async, :async_server]) && !GoodJob.configuration.in_webserver?)
197
197
  end
198
198
 
199
199
  # Whether in +:inline+ execution mode.
@@ -219,21 +219,6 @@ module GoodJob
219
219
 
220
220
  private
221
221
 
222
- # Whether running in a web server process.
223
- # @return [Boolean, nil]
224
- def in_server_process?
225
- return @_in_server_process if defined? @_in_server_process
226
-
227
- @_in_server_process = Rails.const_defined?(:Server) || begin
228
- self_caller = caller
229
-
230
- self_caller.grep(%r{config.ru}).any? || # EXAMPLE: config.ru:3:in `block in <main>' OR config.ru:3:in `new_from_string'
231
- self_caller.grep(%r{puma/request}).any? || # EXAMPLE: puma-5.6.4/lib/puma/request.rb:76:in `handle_request'
232
- self_caller.grep(%{/rack/handler/}).any? || # EXAMPLE: iodine-0.7.44/lib/rack/handler/iodine.rb:13:in `start'
233
- (Concurrent.on_jruby? && self_caller.grep(%r{jruby/rack/rails_booter}).any?) # EXAMPLE: uri:classloader:/jruby/rack/rails_booter.rb:83:in `load_environment'
234
- end
235
- end
236
-
237
222
  def send_notify?(active_job)
238
223
  return false unless GoodJob.configuration.enable_listen_notify
239
224
  return true unless active_job.respond_to?(:good_job_notify)
@@ -79,6 +79,8 @@ module GoodJob
79
79
  def initialize(options, env: ENV)
80
80
  @options = options
81
81
  @env = env
82
+
83
+ @_in_webserver = nil
82
84
  end
83
85
 
84
86
  def validate!
@@ -89,21 +91,24 @@ module GoodJob
89
91
  # for more details on possible values.
90
92
  # @return [Symbol]
91
93
  def execution_mode
92
- mode = if GoodJob::CLI.within_exe?
93
- :external
94
- else
95
- options[:execution_mode] ||
96
- rails_config[:execution_mode] ||
97
- env['GOOD_JOB_EXECUTION_MODE']
98
- end
94
+ mode = options[:execution_mode] ||
95
+ rails_config[:execution_mode] ||
96
+ env['GOOD_JOB_EXECUTION_MODE']
97
+ mode = mode.to_sym if mode
99
98
 
100
99
  if mode
101
- mode.to_sym
100
+ if GoodJob::CLI.within_exe? && [:async, :async_server].include?(mode)
101
+ :external
102
+ else
103
+ mode
104
+ end
105
+ elsif GoodJob::CLI.within_exe?
106
+ :external
102
107
  elsif Rails.env.development?
103
108
  :async
104
109
  elsif Rails.env.test?
105
110
  :inline
106
- else
111
+ else # rubocop:disable Lint/DuplicateBranch
107
112
  :external
108
113
  end
109
114
  end
@@ -173,7 +178,7 @@ module GoodJob
173
178
 
174
179
  # The number of seconds to wait for jobs to finish when shutting down
175
180
  # before stopping the thread. +-1+ is forever.
176
- # @return [Numeric]
181
+ # @return [Float]
177
182
  def shutdown_timeout
178
183
  (
179
184
  options[:shutdown_timeout] ||
@@ -245,7 +250,7 @@ module GoodJob
245
250
 
246
251
  # Number of jobs a {Scheduler} will execute before automatically cleaning up preserved jobs.
247
252
  # Positive values will clean up after that many jobs have run, false or 0 will disable, and -1 will clean up after every job.
248
- # @return [Integer, nil]
253
+ # @return [Integer, Boolean, nil]
249
254
  def cleanup_interval_jobs
250
255
  if rails_config.key?(:cleanup_interval_jobs)
251
256
  value = rails_config[:cleanup_interval_jobs]
@@ -349,6 +354,20 @@ module GoodJob
349
354
  rails_config[:dashboard_default_locale] || DEFAULT_DASHBOARD_DEFAULT_LOCALE
350
355
  end
351
356
 
357
+ # Whether running in a web server process.
358
+ # @return [Boolean, nil]
359
+ def in_webserver?
360
+ return @_in_webserver unless @_in_webserver.nil?
361
+
362
+ @_in_webserver = Rails.const_defined?(:Server) || begin
363
+ self_caller = caller
364
+ self_caller.grep(%r{config.ru}).any? || # EXAMPLE: config.ru:3:in `block in <main>' OR config.ru:3:in `new_from_string'
365
+ self_caller.grep(%r{puma/request}).any? || # EXAMPLE: puma-5.6.4/lib/puma/request.rb:76:in `handle_request'
366
+ self_caller.grep(%{/rack/handler/}).any? || # EXAMPLE: iodine-0.7.44/lib/rack/handler/iodine.rb:13:in `start'
367
+ (Concurrent.on_jruby? && self_caller.grep(%r{jruby/rack/rails_booter}).any?) # EXAMPLE: uri:classloader:/jruby/rack/rails_booter.rb:83:in `load_environment'
368
+ end || false
369
+ end
370
+
352
371
  private
353
372
 
354
373
  def rails_config
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GoodJob
4
4
  # GoodJob gem version.
5
- VERSION = '3.18.0'
5
+ VERSION = '3.18.1'
6
6
 
7
7
  # GoodJob version as Gem::Version object
8
8
  GEM_VERSION = Gem::Version.new(VERSION)
data/lib/good_job.rb CHANGED
@@ -151,6 +151,8 @@ module GoodJob
151
151
  # @param timeout [Numeric] Seconds to wait for active threads to finish.
152
152
  # @return [void]
153
153
  def self.restart(timeout: -1)
154
+ return if configuration.execution_mode != :async && configuration.in_webserver?
155
+
154
156
  _shutdown_all(Capsule.instances, :restart, timeout: timeout)
155
157
  end
156
158
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.18.0
4
+ version: 3.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon