good_job 3.14.0 → 3.14.1

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: 1c0893de944702ad430a2ac00b8e47d740bad60a12a5ae4d009d7c0bcfbeefac
4
- data.tar.gz: bdddfd0a48ba4c93c6a255f31a90eee482b1af65b6fd128973235370ab469c01
3
+ metadata.gz: 4d3457088e2e7120f5660f8c1395adb27887a0aad22d7b2ec816060f7619ebec
4
+ data.tar.gz: a6978f42d4a988b202c891633a8390dd585edbc07cf11f35511aaca005ce67e5
5
5
  SHA512:
6
- metadata.gz: 3dc31d6cb250ad3fd6494718a282aea4982e0e47f3337d4b0601bb8e46bd958edf84ff6e28fa583c45b4071ca1fc68c0deee0f4a763fb98505ea2d4e65d3547e
7
- data.tar.gz: 3937ac0c805118d9ed4c09c7dda525b5dd913190129c2f6bb3bbffe8cc9100716325374d004c86aa6cb623d84a3f5392acea19cbd1bcfbaf0c4585ed9adf7043
6
+ metadata.gz: b5226e5cf17704c8cf1eaa0401fd3bc384d892bb02d6538653bde412b9f627537ba333816e589a05089f590df0d602ab163e57f2cdd4452e5ba539a9c57b7ff3
7
+ data.tar.gz: 49529f8c59b0a62cf6fe0f91b848ef01979c6e245b23e71cc2be3939c3497a6edfe92cb66c6171722e6473ba1d2d759a427855665a6419344ad0dbff69c73783
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.14.1](https://github.com/bensheldon/good_job/tree/v3.14.1) (2023-03-14)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.14.0...v3.14.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Allow joining executions to jobs scoped by state [\#886](https://github.com/bensheldon/good_job/pull/886) ([segiddins](https://github.com/segiddins))
10
+ - 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))
11
+ - 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))
12
+
3
13
  ## [v3.14.0](https://github.com/bensheldon/good_job/tree/v3.14.0) (2023-03-09)
4
14
 
5
15
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.13.0...v3.14.0)
@@ -336,7 +336,7 @@ module GoodJob
336
336
  current_thread.execution_interrupted = performed_at if performed_at
337
337
  update!(performed_at: Time.current)
338
338
 
339
- ActiveSupport::Notifications.instrument("perform_job.good_job", { execution: self, process_id: current_thread.process_id, thread_name: current_thread.thread_name }) do
339
+ 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
340
  value = ActiveJob::Base.execute(active_job_data)
341
341
 
342
342
  if value.is_a?(Exception)
@@ -345,8 +345,14 @@ module GoodJob
345
345
  end
346
346
  handled_error ||= current_thread.error_on_retry || current_thread.error_on_discard
347
347
 
348
+ instrument_payload.merge!(
349
+ value: value,
350
+ handled_error: handled_error,
351
+ retried: current_thread.error_on_retry.present?
352
+ )
348
353
  ExecutionResult.new(value: value, handled_error: handled_error, retried: current_thread.error_on_retry.present?)
349
354
  rescue StandardError => e
355
+ instrument_payload[:unhandled_error] = e
350
356
  ExecutionResult.new(value: nil, unhandled_error: e)
351
357
  end
352
358
  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.1'
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.1
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-14 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