good_job 3.14.0 → 3.14.2

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: 1c0893de944702ad430a2ac00b8e47d740bad60a12a5ae4d009d7c0bcfbeefac
4
- data.tar.gz: bdddfd0a48ba4c93c6a255f31a90eee482b1af65b6fd128973235370ab469c01
3
+ metadata.gz: 6dd3d98377de721a907a5f81384a6c7bda00ae90b08f4a0437bbbb8e453ce4df
4
+ data.tar.gz: 6e6a6f7762bf412b67004b03fc7dd9c0f4bf44917001f13cd5e4b8367329f128
5
5
  SHA512:
6
- metadata.gz: 3dc31d6cb250ad3fd6494718a282aea4982e0e47f3337d4b0601bb8e46bd958edf84ff6e28fa583c45b4071ca1fc68c0deee0f4a763fb98505ea2d4e65d3547e
7
- data.tar.gz: 3937ac0c805118d9ed4c09c7dda525b5dd913190129c2f6bb3bbffe8cc9100716325374d004c86aa6cb623d84a3f5392acea19cbd1bcfbaf0c4585ed9adf7043
6
+ metadata.gz: 4379e0356bb07dd1b49abddc879c1d7005aeb7bf047c0d73843bf22e1d0de262972cd140f4cdd6de57bee2fb29f5ad11519d7f8adcf958bda8d9363343ecf809
7
+ data.tar.gz: 2b93aa27e6b037f5e8debefffdb883c94deb6998640bb21e00284f004a47ca4d41daaf7b4dc9c39a7545d70acd70be2d8532fad7b4057694d5cfbb575d1c769b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.14.2](https://github.com/bensheldon/good_job/tree/v3.14.2) (2023-03-16)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.14.1...v3.14.2)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Bump rack from 2.2.6.3 to 2.2.6.4 [\#893](https://github.com/bensheldon/good_job/pull/893) ([dependabot[bot]](https://github.com/apps/dependabot))
10
+ - Remove non-ActiveRecord::Base backed association [\#892](https://github.com/bensheldon/good_job/pull/892) ([rrunyon](https://github.com/rrunyon))
11
+
12
+ ## [v3.14.1](https://github.com/bensheldon/good_job/tree/v3.14.1) (2023-03-14)
13
+
14
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.14.0...v3.14.1)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - Allow joining executions to jobs scoped by state [\#886](https://github.com/bensheldon/good_job/pull/886) ([segiddins](https://github.com/segiddins))
19
+ - Add execution\_result to event payload for perform\_job.good\_job [\#885](https://github.com/bensheldon/good_job/pull/885) ([segiddins](https://github.com/segiddins))
20
+ - Bump rack from 2.2.6.2 to 2.2.6.3 [\#884](https://github.com/bensheldon/good_job/pull/884) ([dependabot[bot]](https://github.com/apps/dependabot))
21
+
3
22
  ## [v3.14.0](https://github.com/bensheldon/good_job/tree/v3.14.0) (2023-03-09)
4
23
 
5
24
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.13.0...v3.14.0)
@@ -70,7 +70,6 @@ module GoodJob
70
70
  end
71
71
 
72
72
  belongs_to :batch, class_name: 'GoodJob::BatchRecord', optional: true, inverse_of: :executions
73
- belongs_to :batch_callback, class_name: 'GoodJob::Batch', optional: true
74
73
 
75
74
  belongs_to :job, class_name: 'GoodJob::Job', foreign_key: 'active_job_id', primary_key: 'active_job_id', optional: true, inverse_of: :executions
76
75
  after_destroy -> { self.class.active_job_id(active_job_id).delete_all }, if: -> { @_destroy_job }
@@ -336,7 +335,7 @@ module GoodJob
336
335
  current_thread.execution_interrupted = performed_at if performed_at
337
336
  update!(performed_at: Time.current)
338
337
 
339
- ActiveSupport::Notifications.instrument("perform_job.good_job", { execution: self, process_id: current_thread.process_id, thread_name: current_thread.thread_name }) do
338
+ ActiveSupport::Notifications.instrument("perform_job.good_job", { execution: self, process_id: current_thread.process_id, thread_name: current_thread.thread_name }) do |instrument_payload|
340
339
  value = ActiveJob::Base.execute(active_job_data)
341
340
 
342
341
  if value.is_a?(Exception)
@@ -345,8 +344,14 @@ module GoodJob
345
344
  end
346
345
  handled_error ||= current_thread.error_on_retry || current_thread.error_on_discard
347
346
 
347
+ instrument_payload.merge!(
348
+ value: value,
349
+ handled_error: handled_error,
350
+ retried: current_thread.error_on_retry.present?
351
+ )
348
352
  ExecutionResult.new(value: value, handled_error: handled_error, retried: current_thread.error_on_retry.present?)
349
353
  rescue StandardError => e
354
+ instrument_payload[:unhandled_error] = e
350
355
  ExecutionResult.new(value: nil, unhandled_error: e)
351
356
  end
352
357
  end
@@ -23,6 +23,26 @@ module GoodJob
23
23
  def table_name=(_value)
24
24
  raise NotImplementedError, 'Assign GoodJob::Execution.table_name directly'
25
25
  end
26
+
27
+ def json_string(json, attr)
28
+ Arel::Nodes::Grouping.new(Arel::Nodes::InfixOperation.new('->>', json, Arel::Nodes.build_quoted(attr)))
29
+ end
30
+
31
+ def params_job_class
32
+ json_string(arel_table['serialized_params'], 'job_class')
33
+ end
34
+
35
+ def params_execution_count
36
+ Arel::Nodes::InfixOperation.new(
37
+ '::',
38
+ json_string(arel_table['serialized_params'], 'executions'),
39
+ Arel.sql('integer')
40
+ )
41
+ end
42
+
43
+ def coalesce_scheduled_at_created_at
44
+ arel_table.coalesce(arel_table['scheduled_at'], arel_table['created_at'])
45
+ end
26
46
  end
27
47
 
28
48
  self.primary_key = 'active_job_id'
@@ -39,7 +59,7 @@ module GoodJob
39
59
  # @!scope class
40
60
  # @param string [String] Execution class name
41
61
  # @return [ActiveRecord::Relation]
42
- scope :job_class, ->(job_class) { where("serialized_params->>'job_class' = ?", job_class) }
62
+ scope :job_class, ->(name) { where(params_job_class.eq(name)) }
43
63
 
44
64
  # Get Jobs finished before the given timestamp.
45
65
  # @!method finished_before(timestamp)
@@ -49,11 +69,11 @@ module GoodJob
49
69
  scope :finished_before, ->(timestamp) { where(arel_table['finished_at'].lteq(timestamp)) }
50
70
 
51
71
  # First execution will run in the future
52
- scope :scheduled, -> { where(finished_at: nil).where('COALESCE(scheduled_at, created_at) > ?', DateTime.current).where("(serialized_params->>'executions')::integer < 2") }
72
+ scope :scheduled, -> { where(finished_at: nil).where(coalesce_scheduled_at_created_at.gt(DateTime.current)).where(params_execution_count.lt(2)) }
53
73
  # Execution errored, will run in the future
54
- scope :retried, -> { where(finished_at: nil).where('COALESCE(scheduled_at, created_at) > ?', DateTime.current).where("(serialized_params->>'executions')::integer > 1") }
74
+ scope :retried, -> { where(finished_at: nil).where(coalesce_scheduled_at_created_at.gt(DateTime.current)).where(params_execution_count.gt(1)) }
55
75
  # Immediate/Scheduled time to run has passed, waiting for an available thread run
56
- scope :queued, -> { where(finished_at: nil).where('COALESCE(scheduled_at, created_at) <= ?', DateTime.current).joins_advisory_locks.where(pg_locks: { locktype: nil }) }
76
+ scope :queued, -> { where(finished_at: nil).where(coalesce_scheduled_at_created_at.lteq(DateTime.current)).joins_advisory_locks.where(pg_locks: { locktype: nil }) }
57
77
  # Advisory locked and executing
58
78
  scope :running, -> { where(finished_at: nil).joins_advisory_locks.where.not(pg_locks: { locktype: nil }) }
59
79
  # Finished executing (succeeded or discarded)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '3.14.0'
4
+ VERSION = '3.14.2'
5
5
  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.14.0
4
+ version: 3.14.2
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-03-09 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -460,7 +460,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
460
460
  - !ruby/object:Gem::Version
461
461
  version: '0'
462
462
  requirements: []
463
- rubygems_version: 3.4.6
463
+ rubygems_version: 3.4.8
464
464
  signing_key:
465
465
  specification_version: 4
466
466
  summary: A multithreaded, Postgres-based ActiveJob backend for Ruby on Rails