good_job 3.15.10 → 3.15.12

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: 000bb49d312d0103d77ce95d27e79316b7ee66b1056e0566cc1029272442c77a
4
- data.tar.gz: f990fccc402be6ac4dca1e2c8c8f3f57c2a73b00d5c1a065afa1d9ca6645f602
3
+ metadata.gz: 8ba9a6bb5f97a64b3ff00e48501cbebf617372e0983c5f87f14bfe25898625b1
4
+ data.tar.gz: 673df26ced6db84ea48e77c736d8969216497034d0c19ba3f32016fd0b915afd
5
5
  SHA512:
6
- metadata.gz: db26d83de8e6f07447d1ae866ea065a4b8beb37bd9c93d726929b8d0972ba0f862efd641128bffe35e964fcf2589459d60f57751f4b20d7ab16fc1daeb35a82e
7
- data.tar.gz: aae23731a957a0418f13eadc9e2deab3f5378286cb3e40c00f2cf0341dd99d1a0a73f49873835f14c7e2032a4a1738310038752da8e270ac0864591c662811ad
6
+ metadata.gz: 9b39c600a8cb22842c8f2aee4b952695fad309fafb522f16f74ad9b21c20a9db4e9ff05ea13647024c1cbbb95438168cd620be89fb766605419de21e876a2ce8
7
+ data.tar.gz: 8469a0079df3bd25aa8f8474fa5cffe8a67ad7fa91efa70b7e2ebcba50e5132a1880c004e5e6bca2aa3dc12fe844a7cf4219c443644b86c7dde839833a12ab1f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.15.12](https://github.com/bensheldon/good_job/tree/v3.15.12) (2023-06-11)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.11...v3.15.12)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Do not allow GoodJob to automatically start after Rails initialization if previously shutdown [\#976](https://github.com/bensheldon/good_job/pull/976) ([bensheldon](https://github.com/bensheldon))
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Fix Rubocop linting [\#975](https://github.com/bensheldon/good_job/pull/975) ([bensheldon](https://github.com/bensheldon))
14
+ - Bump capybara from 3.38.0 to 3.39.1 [\#970](https://github.com/bensheldon/good_job/pull/970) ([dependabot[bot]](https://github.com/apps/dependabot))
15
+ - Bump thor from 1.2.1 to 1.2.2 [\#967](https://github.com/bensheldon/good_job/pull/967) ([dependabot[bot]](https://github.com/apps/dependabot))
16
+
17
+ ## [v3.15.11](https://github.com/bensheldon/good_job/tree/v3.15.11) (2023-06-06)
18
+
19
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.10...v3.15.11)
20
+
21
+ **Fixed bugs:**
22
+
23
+ - Fix `discrete_executions` job re-enqueueing when `retry_job` is called directly [\#973](https://github.com/bensheldon/good_job/pull/973) ([bensheldon](https://github.com/bensheldon))
24
+
25
+ **Closed issues:**
26
+
27
+ - Unclear how discrete executions should work with reenqueued jobs \(leads to broken job-iteration\) [\#972](https://github.com/bensheldon/good_job/issues/972)
28
+ - `build_for_enqueue` discards `scheduled_at` values for bulk-enqueued jobs [\#966](https://github.com/bensheldon/good_job/issues/966)
29
+
3
30
  ## [v3.15.10](https://github.com/bensheldon/good_job/tree/v3.15.10) (2023-05-22)
4
31
 
5
32
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.9...v3.15.10)
@@ -314,6 +314,8 @@ module GoodJob
314
314
  execution = current_execution
315
315
  execution.assign_attributes(enqueue_args(active_job, { scheduled_at: scheduled_at }))
316
316
  execution.scheduled_at ||= Time.current
317
+ # TODO: these values ideally shouldn't be persisted until the current_execution is finished
318
+ # which will require handling `retry_job` being called from outside the execution context.
317
319
  execution.performed_at = nil
318
320
  execution.finished_at = nil
319
321
  else
@@ -335,7 +337,11 @@ module GoodJob
335
337
  instrument_payload[:execution] = execution
336
338
  execution.save!
337
339
 
338
- CurrentThread.execution.retried_good_job_id = execution.id if retried && !CurrentThread.execution.discrete?
340
+ if retried
341
+ CurrentThread.execution_retried = true
342
+ CurrentThread.execution.retried_good_job_id = execution.id unless current_execution.discrete?
343
+ end
344
+
339
345
  active_job.provider_job_id = execution.id
340
346
  execution
341
347
  end
@@ -402,9 +408,9 @@ module GoodJob
402
408
  instrument_payload.merge!(
403
409
  value: value,
404
410
  handled_error: handled_error,
405
- retried: current_thread.error_on_retry.present?
411
+ retried: current_thread.execution_retried
406
412
  )
407
- ExecutionResult.new(value: value, handled_error: handled_error, retried: current_thread.error_on_retry.present?)
413
+ ExecutionResult.new(value: value, handled_error: handled_error, retried: current_thread.execution_retried)
408
414
  rescue StandardError => e
409
415
  instrument_payload[:unhandled_error] = e
410
416
  ExecutionResult.new(value: nil, unhandled_error: e)
@@ -7,6 +7,9 @@ module GoodJob # :nodoc:
7
7
  include AssignableConnection
8
8
  include Lockable
9
9
 
10
+ STALE_INTERVAL = 30.seconds
11
+ EXPIRED_INTERVAL = 5.minutes
12
+
10
13
  self.table_name = 'good_job_processes'
11
14
 
12
15
  cattr_reader :mutex, default: Mutex.new
@@ -76,5 +79,21 @@ module GoodJob # :nodoc:
76
79
  def basename
77
80
  File.basename(state["proctitle"])
78
81
  end
82
+
83
+ def refresh
84
+ touch(:updated_at) # rubocop:disable Rails/SkipsModelValidations
85
+ end
86
+
87
+ def refresh_if_stale
88
+ refresh if stale?
89
+ end
90
+
91
+ def stale?
92
+ updated_at < STALE_INTERVAL.ago
93
+ end
94
+
95
+ def expired?
96
+ updated_at < EXPIRED_INTERVAL.ago
97
+ end
79
98
  end
80
99
  end
@@ -15,17 +15,18 @@ module GoodJob
15
15
  self.class.instances << self
16
16
  @configuration = configuration
17
17
 
18
- @autostart = true
18
+ @startable = true
19
19
  @running = false
20
20
  @mutex = Mutex.new
21
21
  end
22
22
 
23
- # Start executing jobs (if not already running).
24
- def start
25
- return if @running
23
+ # Start the capsule once. After a shutdown, {#restart} must be used to start again.
24
+ # @return [nil, Boolean] Whether the capsule was started.
25
+ def start(force: false)
26
+ return unless startable?(force: force)
26
27
 
27
28
  @mutex.synchronize do
28
- return if @running
29
+ return unless startable?(force: force)
29
30
 
30
31
  @notifier = GoodJob::Notifier.new(enable_listening: @configuration.enable_listen_notify)
31
32
  @poller = GoodJob::Poller.new(poll_interval: @configuration.poll_interval)
@@ -35,7 +36,7 @@ module GoodJob
35
36
 
36
37
  @cron_manager = GoodJob::CronManager.new(@configuration.cron_entries, start_on_initialize: true) if @configuration.enable_cron?
37
38
 
38
- @autostart = false
39
+ @startable = false
39
40
  @running = true
40
41
  end
41
42
  end
@@ -50,7 +51,7 @@ module GoodJob
50
51
  def shutdown(timeout: :default)
51
52
  timeout = timeout == :default ? @configuration.shutdown_timeout : timeout
52
53
  GoodJob._shutdown_all([@notifier, @poller, @scheduler, @cron_manager].compact, timeout: timeout)
53
- @autostart = false
54
+ @startable = false
54
55
  @running = false
55
56
  end
56
57
 
@@ -61,7 +62,7 @@ module GoodJob
61
62
  raise ArgumentError, "Capsule#restart cannot be called with a timeout of nil" if timeout.nil?
62
63
 
63
64
  shutdown(timeout: timeout)
64
- start
65
+ start(force: true)
65
66
  end
66
67
 
67
68
  # @return [Boolean] Whether the capsule is currently running.
@@ -76,10 +77,16 @@ module GoodJob
76
77
 
77
78
  # Creates an execution thread(s) with the given attributes.
78
79
  # @param job_state [Hash, nil] See {GoodJob::Scheduler#create_thread}.
79
- # @return [Boolean, nil] Whether work was started.
80
+ # @return [Boolean, nil] Whether the thread was created.
80
81
  def create_thread(job_state = nil)
81
- start if !running? && @autostart
82
+ start if startable?
82
83
  @scheduler&.create_thread(job_state)
83
84
  end
85
+
86
+ private
87
+
88
+ def startable?(force: false)
89
+ !@running && (@startable || force)
90
+ end
84
91
  end
85
92
  end
@@ -13,6 +13,7 @@ module GoodJob
13
13
  error_on_retry
14
14
  execution
15
15
  execution_interrupted
16
+ execution_retried
16
17
  ].freeze
17
18
 
18
19
  # @!attribute [rw] cron_at
@@ -51,6 +52,12 @@ module GoodJob
51
52
  # @return [Boolean, nil]
52
53
  thread_mattr_accessor :execution_interrupted
53
54
 
55
+ # @!attribute [rw] execution_retried
56
+ # @!scope class
57
+ # Execution Retried
58
+ # @return [Boolean, nil]
59
+ thread_mattr_accessor :execution_retried
60
+
54
61
  # Resets attributes
55
62
  # @param [Hash] values to assign
56
63
  # @return [void]
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '3.15.10'
4
+ VERSION = '3.15.12'
5
5
 
6
6
  # GoodJob version as Gem::Version object
7
7
  GEM_VERSION = Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.15.10
4
+ version: 3.15.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-22 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob