good_job 3.13.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: c83cf253d12daeb00363fe9c1b3a06b463c6944aa108aa4f884bf43b0d1f5c88
4
- data.tar.gz: 71738f01485fb73b1dfa71396807f4570922d53aa186bf7aa1f9c27b21e4e559
3
+ metadata.gz: 4d3457088e2e7120f5660f8c1395adb27887a0aad22d7b2ec816060f7619ebec
4
+ data.tar.gz: a6978f42d4a988b202c891633a8390dd585edbc07cf11f35511aaca005ce67e5
5
5
  SHA512:
6
- metadata.gz: 25bbd078a94d5079b47d57c267ad72f7e6baa024230add7fd9c693c621eb8be7117aa517f715baba5b16cb5f0378eb0e407a41ea1569e923a16716ef0f4d391b
7
- data.tar.gz: cf58cbaea01a1dd6714b53c6d618661908ccf46ef3deae58b3e2d6063f512e528d0d4f04850e7a3c4a1ccc59ece959a0919d19898488116898f78b9c78c7a5f6
6
+ metadata.gz: b5226e5cf17704c8cf1eaa0401fd3bc384d892bb02d6538653bde412b9f627537ba333816e589a05089f590df0d602ab163e57f2cdd4452e5ba539a9c57b7ff3
7
+ data.tar.gz: 49529f8c59b0a62cf6fe0f91b848ef01979c6e245b23e71cc2be3939c3497a6edfe92cb66c6171722e6473ba1d2d759a427855665a6419344ad0dbff69c73783
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
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
+
13
+ ## [v3.14.0](https://github.com/bensheldon/good_job/tree/v3.14.0) (2023-03-09)
14
+
15
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.13.0...v3.14.0)
16
+
17
+ **Implemented enhancements:**
18
+
19
+ - Deprecate definition of job priority, change to "smaller number is higher priority" to align with Active Job definition [\#883](https://github.com/bensheldon/good_job/pull/883) ([bensheldon](https://github.com/bensheldon))
20
+
3
21
  ## [v3.13.0](https://github.com/bensheldon/good_job/tree/v3.13.0) (2023-03-08)
4
22
 
5
23
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.12.8...v3.13.0)
@@ -108,7 +108,13 @@ module GoodJob
108
108
  # @!method priority_ordered
109
109
  # @!scope class
110
110
  # @return [ActiveRecord::Relation]
111
- scope :priority_ordered, -> { order('priority DESC NULLS LAST') }
111
+ scope :priority_ordered, (lambda do
112
+ if GoodJob.configuration.smaller_number_is_higher_priority
113
+ order('priority ASC NULLS LAST')
114
+ else
115
+ order('priority DESC NULLS LAST')
116
+ end
117
+ end)
112
118
 
113
119
  # Order executions by created_at, for first-in first-out
114
120
  # @!method creation_ordered
@@ -206,6 +212,14 @@ module GoodJob
206
212
 
207
213
  # Construct a GoodJob::Execution from an ActiveJob instance.
208
214
  def self.build_for_enqueue(active_job, overrides = {})
215
+ if active_job.priority && GoodJob.configuration.smaller_number_is_higher_priority.nil?
216
+ ActiveSupport::Deprecation.warn(<<~DEPRECATION)
217
+ The next major version of GoodJob (v4.0) will change job `priority` to give smaller numbers higher priority (default: `0`), in accordance with Active Job's definition of priority.
218
+ To opt-in to this behavior now, set `config.good_job.smaller_number_is_higher_priority = true` in your GoodJob initializer or application.rb.
219
+ To not opt-in yet, but silence this deprecation warning, set `config.good_job.smaller_number_is_higher_priority = false`.
220
+ DEPRECATION
221
+ end
222
+
209
223
  execution_args = {
210
224
  active_job_id: active_job.job_id,
211
225
  queue_name: active_job.queue_name.presence || DEFAULT_QUEUE_NAME,
@@ -322,7 +336,7 @@ module GoodJob
322
336
  current_thread.execution_interrupted = performed_at if performed_at
323
337
  update!(performed_at: Time.current)
324
338
 
325
- 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|
326
340
  value = ActiveJob::Base.execute(active_job_data)
327
341
 
328
342
  if value.is_a?(Exception)
@@ -331,8 +345,14 @@ module GoodJob
331
345
  end
332
346
  handled_error ||= current_thread.error_on_retry || current_thread.error_on_discard
333
347
 
348
+ instrument_payload.merge!(
349
+ value: value,
350
+ handled_error: handled_error,
351
+ retried: current_thread.error_on_retry.present?
352
+ )
334
353
  ExecutionResult.new(value: value, handled_error: handled_error, retried: current_thread.error_on_retry.present?)
335
354
  rescue StandardError => e
355
+ instrument_payload[:unhandled_error] = e
336
356
  ExecutionResult.new(value: nil, unhandled_error: e)
337
357
  end
338
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)
@@ -341,6 +341,10 @@ module GoodJob
341
341
  DEFAULT_ENABLE_LISTEN_NOTIFY
342
342
  end
343
343
 
344
+ def smaller_number_is_higher_priority
345
+ rails_config[:smaller_number_is_higher_priority]
346
+ end
347
+
344
348
  private
345
349
 
346
350
  def rails_config
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '3.13.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.13.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-08 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