good_job 3.16.1 → 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: 364c1bd829e85f9b002b0265bf57b4e29b517ca314ed8335affab915320eb09c
4
- data.tar.gz: 035dc69a55772e2516ac73783cec24bd47c1974a3ba3b3b8a568649985b9a37e
3
+ metadata.gz: 3929d3de9d0c69de6aa34b238573dd19eabb0b6753b28a06b186cfc6972b621b
4
+ data.tar.gz: d927b1cc39f993f64a4b07594cb7215975e02d55cb212b420122b2c672d5f2d4
5
5
  SHA512:
6
- metadata.gz: 124c045c8948530ba298410381bba29717de39b95b1b2fb53c06957c528c86bd84359fe14658b2b2bee84c31c0e83afb85194bca964f6255cc907cf95c72e5c3
7
- data.tar.gz: da74da4e4a00efa81bc995339df665c2a400ac54377078694ba961f8f788c0635b53865b76fee479197e4e478d744888ef393565a854441da935622c5a74a34f
6
+ metadata.gz: 34ac854233932322ad76eaea4d41879b9d97c08a204b6f689affedbe861b86bc5c83b6c02dd1132c267f7f9129d4e0ace042e9299f4fe522fdf9d590b6c0cf33
7
+ data.tar.gz: a8007ea55894eb72494935dff5269d1e54d157eab334b823769884cc3d83d1a37be3d9cb44e603ba5a132cb3993ba8dd8e306c4d3974f9a2bf4dc2603add5706
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
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
+
19
+ ## [v3.16.2](https://github.com/bensheldon/good_job/tree/v3.16.2) (2023-07-13)
20
+
21
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.16.1...v3.16.2)
22
+
23
+ **Closed issues:**
24
+
25
+ - Support for customized job display name [\#956](https://github.com/bensheldon/good_job/issues/956)
26
+
27
+ **Merged pull requests:**
28
+
29
+ - Add `GoodJob::Job#display_name` to allow customizing dashboard job display [\#1008](https://github.com/bensheldon/good_job/pull/1008) ([paul](https://github.com/paul))
30
+
3
31
  ## [v3.16.1](https://github.com/bensheldon/good_job/tree/v3.16.1) (2023-07-11)
4
32
 
5
33
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.16.0...v3.16.1)
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.
@@ -149,6 +145,12 @@ module GoodJob
149
145
  })
150
146
  end
151
147
 
148
+ # Used when displaying this job in the GoodJob dashboard.
149
+ # @return [String]
150
+ def display_name
151
+ job_class
152
+ end
153
+
152
154
  # Tests whether the job is being executed right now.
153
155
  # @return [Boolean]
154
156
  def running?
@@ -222,9 +224,12 @@ module GoodJob
222
224
 
223
225
  update_execution = proc do
224
226
  execution.update(
225
- finished_at: Time.current,
226
- error: GoodJob::Execution.format_error(job_error),
227
- 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
228
233
  )
229
234
  end
230
235
 
@@ -23,7 +23,7 @@
23
23
  <div class="row align-items-center">
24
24
  <div class="col-lg-4">
25
25
  <%= tag.code link_to(job.id, job_path(job), class: "small text-muted text-decoration-none") %>
26
- <%= tag.h5 tag.code(link_to(job.job_class, job_path(job), class: "text-reset text-decoration-none")), class: "text-reset mb-0" %>
26
+ <%= tag.h5 tag.code(link_to(job.display_name, job_path(job), class: "text-reset text-decoration-none")), class: "text-reset mb-0" %>
27
27
  </div>
28
28
  <div class="col-4 col-lg-1 text-lg-center">
29
29
  <div class="d-lg-none small text-muted mt-1"><%=t "good_job.models.job.queue" %></div>
@@ -64,7 +64,7 @@
64
64
  <%= check_box_tag 'job_ids[]', job.id, false, id: dom_id(job, :checkbox), data: { "checkbox-toggle-each": "job_ids" } %>
65
65
  <div class="ms-2">
66
66
  <%= tag.code link_to(job.id, job_path(job), class: "small text-muted text-decoration-none") %>
67
- <%= tag.h5 tag.code(link_to(job.job_class, job_path(job), class: "text-reset text-decoration-none")), class: "text-reset mb-0" %>
67
+ <%= tag.h5 tag.code(link_to(job.display_name, job_path(job), class: "text-reset text-decoration-none")), class: "text-reset mb-0" %>
68
68
  <% if job.error %>
69
69
  <div class="mt-1 small">
70
70
  <strong class="small"><%=t "good_job.shared.error" %>:</strong>
@@ -13,7 +13,7 @@
13
13
  </nav>
14
14
  <div class="row align-items-center">
15
15
  <div class="col-md-5">
16
- <h2 class="mb-2 mb-md-0"><%= tag.code @job.job_class %></h2>
16
+ <h2 class="mb-2 mb-md-0"><%= tag.code @job.display_name %></h2>
17
17
  </div>
18
18
  <div class="col-6 col-md-2">
19
19
  <div class="small text-muted text-uppercase"><%= t "good_job.models.job.queue" %></div>
@@ -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.1'
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.1
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-11 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