good_job 1.11.0 → 1.11.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: 6c0b45fcd80fbd536af0f6fed44ef53f446ee6574f7e90d41a38585ec8b3ba63
4
- data.tar.gz: 8b45f77d94bd809b25fb725f57622f1966f188157f235e03c56442817e31afd4
3
+ metadata.gz: 91a09f77d3cb46eb91c4673732e1c52ea752f8d94f95c23c81d3457dc63aa051
4
+ data.tar.gz: ef21168d4aa96f3dfbf50ebed2339132bea52542209d5732d84ac23028227537
5
5
  SHA512:
6
- metadata.gz: 820a1847c2dfce6456d925fe73e8373d5b2f19ff9bc2dd143dbf942acfb0c3872b4fdd1dc888741ae7f3974c7f6869ef82ef8c54bd238ceea03bb63ff8829593
7
- data.tar.gz: 4faa2442654f37475c22ce7c3e3b440351a5f91a53ac2ada273cba764c409e7f7f108c26b463a736b9880d4097ef9096775905c092bf5860805e3cf7bffede86
6
+ metadata.gz: 8140a558ee43eeb2e3673462b7279f25cbed256bac385b131aa48c2f0ff59106d2038a39c65f3f1fd11f65cbcf7d3fb232bbfd20c790e7de629047a8eaed742b
7
+ data.tar.gz: 9daf8d432f5a013fbe5af10176b788c6c2e8c89e0f9b5e12568cbef7a7ecddda2b9296968e1076f71e5f26ed35a2f37d987227e7ad260030807f95404c7dbdeb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.11.1](https://github.com/bensheldon/good_job/tree/v1.11.1) (2021-07-07)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.0...v1.11.1)
6
+
7
+ **Closed issues:**
8
+
9
+ - Database connection required while loading the code on 1.10.x [\#291](https://github.com/bensheldon/good_job/issues/291)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Defer accessing ActiveRecord `primary_key` in Lockable [\#293](https://github.com/bensheldon/good_job/pull/293) ([bensheldon](https://github.com/bensheldon))
14
+
3
15
  ## [v1.11.0](https://github.com/bensheldon/good_job/tree/v1.11.0) (2021-07-07)
4
16
 
5
17
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.10.1...v1.11.0)
@@ -23,20 +23,20 @@ module GoodJob
23
23
 
24
24
  included do
25
25
  # Default column to be used when creating Advisory Locks
26
- cattr_accessor(:advisory_lockable_column, instance_accessor: false) { primary_key }
26
+ class_attribute :advisory_lockable_column, instance_accessor: false, default: Concurrent::Delay.new { primary_key }
27
27
 
28
28
  # Default Postgres function to be used for Advisory Locks
29
- cattr_accessor(:advisory_lockable_function) { "pg_try_advisory_lock" }
29
+ class_attribute :advisory_lockable_function, default: "pg_try_advisory_lock"
30
30
 
31
31
  # Attempt to acquire an advisory lock on the selected records and
32
32
  # return only those records for which a lock could be acquired.
33
- # @!method advisory_lock(column: advisory_lockable_column, function: advisory_lockable_function)
33
+ # @!method advisory_lock(column: _advisory_lockable_column, function: advisory_lockable_function)
34
34
  # @!scope class
35
35
  # @param column [String, Symbol] column values to Advisory Lock against
36
36
  # @param function [String, Symbol] Postgres Advisory Lock function name to use
37
37
  # @return [ActiveRecord::Relation]
38
38
  # A relation selecting only the records that were locked.
39
- scope :advisory_lock, (lambda do |column: advisory_lockable_column, function: advisory_lockable_function|
39
+ scope :advisory_lock, (lambda do |column: _advisory_lockable_column, function: advisory_lockable_function|
40
40
  original_query = self
41
41
 
42
42
  cte_table = Arel::Table.new(:rows)
@@ -64,13 +64,13 @@ module GoodJob
64
64
  #
65
65
  # For details on +pg_locks+, see
66
66
  # {https://www.postgresql.org/docs/current/view-pg-locks.html}.
67
- # @!method joins_advisory_locks(column: advisory_lockable_column)
67
+ # @!method joins_advisory_locks(column: _advisory_lockable_column)
68
68
  # @!scope class
69
69
  # @param column [String, Symbol] column values to Advisory Lock against
70
70
  # @return [ActiveRecord::Relation]
71
71
  # @example Get the records that have a session awaiting a lock:
72
72
  # MyLockableRecord.joins_advisory_locks.where("pg_locks.granted = ?", false)
73
- scope :joins_advisory_locks, (lambda do |column: advisory_lockable_column|
73
+ scope :joins_advisory_locks, (lambda do |column: _advisory_lockable_column|
74
74
  join_sql = <<~SQL.squish
75
75
  LEFT JOIN pg_locks ON pg_locks.locktype = 'advisory'
76
76
  AND pg_locks.objsubid = 1
@@ -82,26 +82,26 @@ module GoodJob
82
82
  end)
83
83
 
84
84
  # Find records that do not have an advisory lock on them.
85
- # @!method advisory_unlocked(column: advisory_lockable_column)
85
+ # @!method advisory_unlocked(column: _advisory_lockable_column)
86
86
  # @!scope class
87
87
  # @param column [String, Symbol] column values to Advisory Lock against
88
88
  # @return [ActiveRecord::Relation]
89
- scope :advisory_unlocked, ->(column: advisory_lockable_column) { joins_advisory_locks(column: column).where(pg_locks: { locktype: nil }) }
89
+ scope :advisory_unlocked, ->(column: _advisory_lockable_column) { joins_advisory_locks(column: column).where(pg_locks: { locktype: nil }) }
90
90
 
91
91
  # Find records that have an advisory lock on them.
92
- # @!method advisory_locked(column: advisory_lockable_column)
92
+ # @!method advisory_locked(column: _advisory_lockable_column)
93
93
  # @!scope class
94
94
  # @param column [String, Symbol] column values to Advisory Lock against
95
95
  # @return [ActiveRecord::Relation]
96
- scope :advisory_locked, ->(column: advisory_lockable_column) { joins_advisory_locks(column: column).where.not(pg_locks: { locktype: nil }) }
96
+ scope :advisory_locked, ->(column: _advisory_lockable_column) { joins_advisory_locks(column: column).where.not(pg_locks: { locktype: nil }) }
97
97
 
98
98
  # Find records with advisory locks owned by the current Postgres
99
99
  # session/connection.
100
- # @!method advisory_locked(column: advisory_lockable_column)
100
+ # @!method advisory_locked(column: _advisory_lockable_column)
101
101
  # @!scope class
102
102
  # @param column [String, Symbol] column values to Advisory Lock against
103
103
  # @return [ActiveRecord::Relation]
104
- scope :owns_advisory_locked, ->(column: advisory_lockable_column) { joins_advisory_locks(column: column).where('"pg_locks"."pid" = pg_backend_pid()') }
104
+ scope :owns_advisory_locked, ->(column: _advisory_lockable_column) { joins_advisory_locks(column: column).where('"pg_locks"."pid" = pg_backend_pid()') }
105
105
 
106
106
  # Whether an advisory lock should be acquired in the same transaction
107
107
  # that created the record.
@@ -143,7 +143,7 @@ module GoodJob
143
143
  # MyLockableRecord.order(created_at: :asc).limit(2).with_advisory_lock do |record|
144
144
  # do_something_with record
145
145
  # end
146
- def with_advisory_lock(column: advisory_lockable_column, function: advisory_lockable_function, unlock_session: false)
146
+ def with_advisory_lock(column: _advisory_lockable_column, function: advisory_lockable_function, unlock_session: false)
147
147
  raise ArgumentError, "Must provide a block" unless block_given?
148
148
 
149
149
  records = advisory_lock(column: column, function: function).to_a
@@ -154,13 +154,19 @@ module GoodJob
154
154
  advisory_unlock_session
155
155
  else
156
156
  records.each do |record|
157
- key = [table_name, record[advisory_lockable_column]].join
157
+ key = [table_name, record[_advisory_lockable_column]].join
158
158
  record.advisory_unlock(key: key, function: advisory_unlockable_function(function))
159
159
  end
160
160
  end
161
161
  end
162
162
  end
163
163
 
164
+ # Allow advisory_lockable_column to be a `Concurrent::Delay`
165
+ def _advisory_lockable_column
166
+ column = advisory_lockable_column
167
+ column.respond_to?(:value) ? column.value : column
168
+ end
169
+
164
170
  def supports_cte_materialization_specifiers?
165
171
  return @_supports_cte_materialization_specifiers if defined?(@_supports_cte_materialization_specifiers)
166
172
 
@@ -308,7 +314,7 @@ module GoodJob
308
314
  # Default Advisory Lock key
309
315
  # @return [String]
310
316
  def lockable_key
311
- [self.class.table_name, self[self.class.advisory_lockable_column]].join
317
+ [self.class.table_name, self[self.class._advisory_lockable_column]].join
312
318
  end
313
319
 
314
320
  delegate :pg_or_jdbc_query, to: :class
@@ -1,4 +1,4 @@
1
1
  module GoodJob
2
2
  # GoodJob gem version.
3
- VERSION = '1.11.0'.freeze
3
+ VERSION = '1.11.1'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon