good_job 3.10.0 → 3.10.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: 22496fe725c6ad616c39f243cf8f53381dee64a5402d3a199c8c604bff2c4eb3
4
- data.tar.gz: 6d9791dd28f28ddf9317f2770029323754fa32c60403f336f23db8020cdecc51
3
+ metadata.gz: 3e632ae76e69e8601479181fb0093e9c6777510ac0743184a8f578b3c4dacee8
4
+ data.tar.gz: 577f36ad182e6f4ff841abcd073925f4477f1086b1a0c7a454c12037f781ace7
5
5
  SHA512:
6
- metadata.gz: e182b3aa78b38fd75baa5e0c14704baa99b7aa98f34ff011006543ce7a356e6eae8ac45e605d65d985b8631f6f185666f78e5bb1be1f39feebd62c159535a7e5
7
- data.tar.gz: acf8a1f601e07142b0dbaea2f2e229fa3d9b7f8c50dd6232531f8ff50cf888d61f88f2a02ae423ffaa8a9a6533bd1cd0522e7cfa849abb20db8dc538adf75ae3
6
+ metadata.gz: f9211423d43cee468602aa1476d0d4b71a3831448157dc7dc540f98e0d1cb476e60bed884679ef10733af21c21e1c595dac14dc2d1c0b25d4b49b8d246f7be98
7
+ data.tar.gz: 25a51a4196ea6618ca44ac73ed6cb9f97b63d99596bd144a9d51f439033a22d15ab16a73cd9d48954dc9b447b19cc9f03a21a9e5667d5021c85b5510ad7ca577
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.10.1](https://github.com/bensheldon/good_job/tree/v3.10.1) (2023-02-06)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.10.0...v3.10.1)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Ensure batch is reloaded before updating on multiple enqueues [\#824](https://github.com/bensheldon/good_job/pull/824) ([bensheldon](https://github.com/bensheldon))
10
+
11
+ **Closed issues:**
12
+
13
+ - Can't batch.enqueue the callback after retrying a job within the batch [\#822](https://github.com/bensheldon/good_job/issues/822)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - In tests, retry when connecting to Puma returns Net::ReadTimeout [\#825](https://github.com/bensheldon/good_job/pull/825) ([bensheldon](https://github.com/bensheldon))
18
+ - Add Batch enqueue example to Demo's cron configuration [\#823](https://github.com/bensheldon/good_job/pull/823) ([bensheldon](https://github.com/bensheldon))
19
+
3
20
  ## [v3.10.0](https://github.com/bensheldon/good_job/tree/v3.10.0) (2023-02-04)
4
21
 
5
22
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.9.0...v3.10.0)
@@ -86,15 +86,23 @@ module GoodJob
86
86
  # @return [Array<ActiveJob::Base>] Active jobs added to the batch
87
87
  def enqueue(active_jobs = [], **properties, &block)
88
88
  assign_properties(properties)
89
- record.save!
89
+ if record.new_record?
90
+ record.save!
91
+ else
92
+ record.with_advisory_lock(function: "pg_advisory_lock") do
93
+ record.enqueued_at_will_change!
94
+ record.finished_at_will_change!
95
+ record.update!(enqueued_at: nil, finished_at: nil)
96
+ end
97
+ end
90
98
 
91
99
  active_jobs = add(active_jobs, &block)
92
100
 
93
- record.finished_at = nil
94
- record.enqueued_at = Time.current if enqueued_at.nil?
95
- record.save!
101
+ record.with_advisory_lock(function: "pg_advisory_lock") do
102
+ record.update!(enqueued_at: Time.current)
103
+ record._continue_discard_or_finish(lock: false)
104
+ end
96
105
 
97
- record._continue_discard_or_finish
98
106
  active_jobs
99
107
  end
100
108
 
@@ -43,16 +43,17 @@ module GoodJob
43
43
  attributes.except('serialized_properties').merge(properties: properties)
44
44
  end
45
45
 
46
- def _continue_discard_or_finish(execution = nil)
46
+ def _continue_discard_or_finish(execution = nil, lock: true)
47
47
  execution_discarded = execution && execution.error.present? && execution.retried_good_job_id.nil?
48
- with_advisory_lock(function: "pg_advisory_lock") do
48
+ take_advisory_lock(lock) do
49
49
  Batch.within_thread(batch_id: nil, batch_callback_id: id) do
50
- if execution_discarded && discarded_at.blank?
50
+ reload
51
+ if execution_discarded && !discarded_at
51
52
  update(discarded_at: Time.current)
52
53
  on_discard.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :discard }) if on_discard.present?
53
54
  end
54
55
 
55
- if !finished_at && enqueued_at && jobs.where(finished_at: nil).count.zero?
56
+ if enqueued_at && !finished_at && jobs.where(finished_at: nil).count.zero?
56
57
  update(finished_at: Time.current)
57
58
  on_success.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :success }) if !discarded_at && on_success.present?
58
59
  on_finish.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :finish }) if on_finish.present?
@@ -80,5 +81,15 @@ module GoodJob
80
81
 
81
82
  self.serialized_properties = value
82
83
  end
84
+
85
+ private
86
+
87
+ def take_advisory_lock(value, &block)
88
+ if value
89
+ with_advisory_lock(function: "pg_advisory_lock", &block)
90
+ else
91
+ yield
92
+ end
93
+ end
83
94
  end
84
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '3.10.0'
4
+ VERSION = '3.10.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.10.0
4
+ version: 3.10.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-02-04 00:00:00.000000000 Z
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob