good_job 3.16.2 → 3.16.3

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: df700f1e4e911894d7f47d8b46c6159200e9f68bc6c7db9c9d8592999320851f
4
- data.tar.gz: 0f8994e16848891c3a2a41064b8ee12555c9880035735ed1635a6ffd888ef276
3
+ metadata.gz: 3929d3de9d0c69de6aa34b238573dd19eabb0b6753b28a06b186cfc6972b621b
4
+ data.tar.gz: d927b1cc39f993f64a4b07594cb7215975e02d55cb212b420122b2c672d5f2d4
5
5
  SHA512:
6
- metadata.gz: f73d66cf94b957e59aaf4352d0bd0f0e4d5477144875a5923f846f5dadaf938b7a3f6c1f0cf21ae353258145e5ad2f4cc4c98a5c433d77c6b45b74c315358cdc
7
- data.tar.gz: 99a1ba23209daa2890fee61443a91ff61a5ce2c8b7a5c5eeb55f54d85cc8166b97c3551d132a765ef6907924c78291e52d1b5cec705a9829f833f688506ecd76
6
+ metadata.gz: 34ac854233932322ad76eaea4d41879b9d97c08a204b6f689affedbe861b86bc5c83b6c02dd1132c267f7f9129d4e0ace042e9299f4fe522fdf9d590b6c0cf33
7
+ data.tar.gz: a8007ea55894eb72494935dff5269d1e54d157eab334b823769884cc3d83d1a37be3d9cb44e603ba5a132cb3993ba8dd8e306c4d3974f9a2bf4dc2603add5706
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.16.3](https://github.com/bensheldon/good_job/tree/v3.16.3) (2023-07-18)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.16.2...v3.16.3)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Fix bulk enqueue for unmigrated 'error\_event'; add `GoodJob.migrated?` check method; use custom enum implementation [\#1011](https://github.com/bensheldon/good_job/pull/1011) ([bensheldon](https://github.com/bensheldon))
10
+
11
+ **Closed issues:**
12
+
13
+ - GoodJob::Bulk.enqueue not handling missing migrations [\#1010](https://github.com/bensheldon/good_job/issues/1010)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Move shared `BaseExecution` concerns into the base class. [\#1009](https://github.com/bensheldon/good_job/pull/1009) ([dixpac](https://github.com/dixpac))
18
+
3
19
  ## [v3.16.2](https://github.com/bensheldon/good_job/tree/v3.16.2) (2023-07-13)
4
20
 
5
21
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.16.1...v3.16.2)
data/README.md CHANGED
@@ -703,7 +703,9 @@ GoodJob follows semantic versioning, though updates may be encouraged through de
703
703
 
704
704
  #### Upgrading minor versions
705
705
 
706
- Upgrading between minor versions (e.g. v1.4 to v1.5) should not introduce breaking changes, but can introduce new deprecation warnings and database migration notices.
706
+ Upgrading between minor versions (e.g. v1.4 to v1.5) should not introduce breaking changes, but can introduce new deprecation warnings and database migration warnings.
707
+
708
+ Database migrations introduced in minor releases are _not required_ to be applied until the next major release. If you would like apply newly introduced migrations immediately, assert `GoodJob.migrated?` in your application's test suite.
707
709
 
708
710
  To perform upgrades to the GoodJob database tables:
709
711
 
@@ -14,15 +14,32 @@ module GoodJob
14
14
  ERROR_EVENT_DISCARDED = 'discarded',
15
15
  ].freeze
16
16
 
17
- included do
18
- enum error_event: {
19
- ERROR_EVENT_INTERRUPTED => 0,
20
- ERROR_EVENT_UNHANDLED => 1,
21
- ERROR_EVENT_HANDLED => 2,
22
- ERROR_EVENT_RETRIED => 3,
23
- ERROR_EVENT_RETRY_STOPPED => 4,
24
- ERROR_EVENT_DISCARDED => 5,
25
- }.freeze, _prefix: :error_event
17
+ ERROR_EVENT_ENUMS = {
18
+ ERROR_EVENT_INTERRUPTED => 0,
19
+ ERROR_EVENT_UNHANDLED => 1,
20
+ ERROR_EVENT_HANDLED => 2,
21
+ ERROR_EVENT_RETRIED => 3,
22
+ ERROR_EVENT_RETRY_STOPPED => 4,
23
+ ERROR_EVENT_DISCARDED => 5,
24
+ }.freeze
25
+
26
+ # TODO: GoodJob v4 can make this an `enum` once migrations are guaranteed.
27
+ def error_event
28
+ return unless self.class.columns_hash['error_event']
29
+
30
+ enum = super
31
+ return unless enum
32
+
33
+ ERROR_EVENT_ENUMS.key(enum)
34
+ end
35
+
36
+ def error_event=(event)
37
+ return unless self.class.columns_hash['error_event']
38
+
39
+ enum = ERROR_EVENT_ENUMS[event]
40
+ raise(ArgumentError, "Invalid error_event: #{event}") if event && !enum
41
+
42
+ super(enum)
26
43
  end
27
44
  end
28
45
  end
@@ -5,6 +5,9 @@ module GoodJob
5
5
  # which both read out of the same table.
6
6
  class BaseExecution < BaseRecord
7
7
  include ErrorEvents
8
+ include Filterable
9
+ include Lockable
10
+ include Reportable
8
11
 
9
12
  self.table_name = 'good_jobs'
10
13
 
@@ -3,10 +3,6 @@
3
3
  module GoodJob
4
4
  # ActiveRecord model that represents an +ActiveJob+ job.
5
5
  class Execution < BaseExecution
6
- include Lockable
7
- include Filterable
8
- include Reportable
9
-
10
6
  # Raised if something attempts to execute a previously completed Execution again.
11
7
  PreviouslyPerformedError = Class.new(StandardError)
12
8
 
@@ -384,7 +380,7 @@ module GoodJob
384
380
  error: interrupt_error_string,
385
381
  finished_at: Time.current,
386
382
  }
387
- discrete_execution_attrs[:error_event] = GoodJob::DiscreteExecution.error_events[GoodJob::DiscreteExecution::ERROR_EVENT_INTERRUPTED] if self.class.error_event_migrated?
383
+ discrete_execution_attrs[:error_event] = GoodJob::ErrorEvents::ERROR_EVENT_ENUMS[GoodJob::ErrorEvents::ERROR_EVENT_INTERRUPTED] if self.class.error_event_migrated?
388
384
  discrete_executions.where(finished_at: nil).where.not(performed_at: nil).update_all(discrete_execution_attrs) # rubocop:disable Rails/SkipsModelValidations
389
385
  end
390
386
  end
@@ -7,10 +7,6 @@ module GoodJob
7
7
  # A single row from the +good_jobs+ table of executions is fetched to represent a Job.
8
8
  #
9
9
  class Job < BaseExecution
10
- include Filterable
11
- include Lockable
12
- include Reportable
13
-
14
10
  # Raised when an inappropriate action is applied to a Job based on its state.
15
11
  ActionForStateMismatchError = Class.new(StandardError)
16
12
  # Raised when an action requires GoodJob to be the ActiveJob Queue Adapter but GoodJob is not.
@@ -228,9 +224,12 @@ module GoodJob
228
224
 
229
225
  update_execution = proc do
230
226
  execution.update(
231
- finished_at: Time.current,
232
- error: GoodJob::Execution.format_error(job_error),
233
- error_event: :discarded
227
+ {
228
+ finished_at: Time.current,
229
+ error: GoodJob::Execution.format_error(job_error),
230
+ }.tap do |attrs|
231
+ attrs[:error_event] = ERROR_EVENT_DISCARDED if self.class.error_event_migrated?
232
+ end
234
233
  )
235
234
  end
236
235
 
@@ -64,7 +64,15 @@ module GoodJob
64
64
 
65
65
  inline_executions = []
66
66
  GoodJob::Execution.transaction(requires_new: true, joinable: false) do
67
- results = GoodJob::Execution.insert_all(executions.map(&:attributes), returning: %w[id active_job_id]) # rubocop:disable Rails/SkipsModelValidations
67
+ execution_attributes = executions.map do |execution|
68
+ if GoodJob::Execution.error_event_migrated?
69
+ execution.attributes
70
+ else
71
+ execution.attributes.except('error_event')
72
+ end
73
+ end
74
+
75
+ results = GoodJob::Execution.insert_all(execution_attributes, returning: %w[id active_job_id]) # rubocop:disable Rails/SkipsModelValidations
68
76
 
69
77
  job_id_to_provider_job_id = results.each_with_object({}) { |result, hash| hash[result['active_job_id']] = result['id'] }
70
78
  active_jobs.each do |active_job|
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GoodJob
4
4
  # GoodJob gem version.
5
- VERSION = '3.16.2'
5
+ VERSION = '3.16.3'
6
6
 
7
7
  # GoodJob version as Gem::Version object
8
8
  GEM_VERSION = Gem::Version.new(VERSION)
data/lib/good_job.rb CHANGED
@@ -246,5 +246,14 @@ module GoodJob
246
246
  end
247
247
  end
248
248
 
249
+ # Whether all GoodJob migrations have been applied.
250
+ # For use in tests/CI to validate GoodJob is up-to-date.
251
+ # @return [Boolean]
252
+ def self.migrated?
253
+ # Always update with the most recent migration check
254
+ GoodJob::Execution.reset_column_information
255
+ GoodJob::Execution.error_event_migrated?
256
+ end
257
+
249
258
  ActiveSupport.run_load_hooks(:good_job, self)
250
259
  end
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.16.2
4
+ version: 3.16.3
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-07-13 00:00:00.000000000 Z
11
+ date: 2023-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob