good_job 1.9.0 → 1.9.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: 68ed9e19332edf1b6aa736b94980c1cc6eb08a3dbee67efad71852ed69220d23
4
- data.tar.gz: bdf36f6d86f203de02dd647bd3a245564645e18331f97dda6dcca748876153d0
3
+ metadata.gz: 00e281a3f0c203b1401da29f633584c6bb1bb050139413c1c3762fddce8d0555
4
+ data.tar.gz: c7d9e2e3e2e401d0d8872f66890be0901b33cb8d774860d4885b334d215248e8
5
5
  SHA512:
6
- metadata.gz: 6ecb2b42f43865aa9f9b1677438d727ff2c74ec003acd739fde3688d50dfc72e23bf61ab9cf8b12de519e31c56142a5ba79bbfa27bf09db74d829e95a1b11e30
7
- data.tar.gz: f9c2038d1e4688cd83d23b0530071a447ee0b1692d7857a5e72b4814d8fb56496aca3aceb63b340542e518e8d0e9eeb29bf5a0ecf6d7f7da18825796cc6bee26
6
+ metadata.gz: d3aa584ac5c42dfeae93596168195652a7d030c38e197467204ef1c1a03f5ff4187d9c3d45e5549d4c1eae739ec5859e0a664dc74c1d1a685fc8547357682f27
7
+ data.tar.gz: e420f7e40d16ef19f3392da7fd249887e94b805af976a740f76a237131dd2afcc05b4e29c616b63738d44070470a0c32ceefca808707afeab8fc7e6543d3b623
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.9.1](https://github.com/bensheldon/good_job/tree/v1.9.1) (2021-04-19)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.9.0...v1.9.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Allow to specify parent class for active record [\#238](https://github.com/bensheldon/good_job/pull/238) ([morgoth](https://github.com/morgoth))
10
+
3
11
  ## [v1.9.0](https://github.com/bensheldon/good_job/tree/v1.9.0) (2021-04-16)
4
12
 
5
13
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.8.0...v1.9.0)
data/README.md CHANGED
@@ -255,6 +255,7 @@ config.good_job.execution_mode = :external
255
255
 
256
256
  Good Job’s general behavior can also be configured via several attributes directly on the `GoodJob` module:
257
257
 
258
+ - **`GoodJob.active_record_parent_class`** (string) The ActiveRecord parent class inherited by GoodJob's ActiveRecord model `GoodJob::Job` (defaults to `"ActiveRecord::Base"`). Configure this when using [multiple databases with ActiveRecord](https://guides.rubyonrails.org/active_record_multiple_databases.html) or when other custom configuration is necessary for the ActiveRecord model to connect to the Postgres database. _The value must be a String to avoid premature initialization of ActiveRecord._
258
259
  - **`GoodJob.logger`** ([Rails Logger](https://api.rubyonrails.org/classes/ActiveSupport/Logger.html)) lets you set a custom logger for GoodJob. It should be an instance of a Rails `Logger`.
259
260
  - **`GoodJob.preserve_job_records`** (boolean) keeps job records in your database even after jobs are completed. (Default: `false`)
260
261
  - **`GoodJob.retry_on_unhandled_error`** (boolean) causes jobs to be re-queued and retried if they raise an instance of `StandardError`. Instances of `Exception`, like SIGINT, will *always* be retried, regardless of this attribute’s value. (Default: `true`)
@@ -264,6 +265,7 @@ You’ll generally want to configure these in `config/initializers/good_job.rb`,
264
265
 
265
266
  ```ruby
266
267
  # config/initializers/good_job.rb
268
+ GoodJob.active_record_parent_class = "ApplicationRecord"
267
269
  GoodJob.preserve_job_records = true
268
270
  GoodJob.retry_on_unhandled_error = false
269
271
  GoodJob.on_thread_error = -> (exception) { Raven.capture_exception(exception) }
data/lib/good_job.rb CHANGED
@@ -17,6 +17,15 @@ require "good_job/railtie"
17
17
  #
18
18
  # +GoodJob+ is the top-level namespace and exposes configuration attributes.
19
19
  module GoodJob
20
+ # @!attribute [rw] active_record_parent_class
21
+ # @!scope class
22
+ # The ActiveRecord parent class inherited by +GoodJob::Job+ (default: +ActiveRecord::Base+).
23
+ # Use this when using multiple databases or other custom ActiveRecord configuration.
24
+ # @return [ActiveRecord::Base]
25
+ # @example Change the base class:
26
+ # GoodJob.active_record_parent_class = "CustomApplicationRecord"
27
+ mattr_accessor :active_record_parent_class, default: "ActiveRecord::Base"
28
+
20
29
  # @!attribute [rw] logger
21
30
  # @!scope class
22
31
  # The logger used by GoodJob (default: +Rails.logger+).
data/lib/good_job/job.rb CHANGED
@@ -2,7 +2,7 @@ module GoodJob
2
2
  #
3
3
  # Represents a request to perform an +ActiveJob+ job.
4
4
  #
5
- class Job < ActiveRecord::Base
5
+ class Job < Object.const_get(GoodJob.active_record_parent_class)
6
6
  include Lockable
7
7
 
8
8
  # Raised if something attempts to execute a previously completed Job again.
@@ -143,7 +143,7 @@ module GoodJob
143
143
  def supports_cte_materialization_specifiers?
144
144
  return @_supports_cte_materialization_specifiers if defined?(@_supports_cte_materialization_specifiers)
145
145
 
146
- @_supports_cte_materialization_specifiers = ActiveRecord::Base.connection.postgresql_version >= 120000
146
+ @_supports_cte_materialization_specifiers = connection.postgresql_version >= 120000
147
147
  end
148
148
  end
149
149
 
@@ -158,7 +158,7 @@ module GoodJob
158
158
  WHERE pg_try_advisory_lock(('x'||substr(md5($1 || $2::text), 1, 16))::bit(64)::bigint)
159
159
  SQL
160
160
  binds = [[nil, self.class.table_name], [nil, send(self.class.primary_key)]]
161
- ActiveRecord::Base.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?
161
+ self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?
162
162
  end
163
163
 
164
164
  # Releases an advisory lock on this record if it is locked by this database
@@ -36,7 +36,7 @@ module GoodJob # :nodoc:
36
36
  # Send a message via Postgres NOTIFY
37
37
  # @param message [#to_json]
38
38
  def self.notify(message)
39
- connection = ActiveRecord::Base.connection
39
+ connection = Job.connection
40
40
  connection.exec_query <<~SQL.squish
41
41
  NOTIFY #{CHANNEL}, #{connection.quote(message.to_json)}
42
42
  SQL
@@ -159,8 +159,8 @@ module GoodJob # :nodoc:
159
159
  end
160
160
 
161
161
  def with_listen_connection
162
- ar_conn = ActiveRecord::Base.connection_pool.checkout.tap do |conn|
163
- ActiveRecord::Base.connection_pool.remove(conn)
162
+ ar_conn = Job.connection_pool.checkout.tap do |conn|
163
+ Job.connection_pool.remove(conn)
164
164
  end
165
165
  pg_conn = ar_conn.raw_connection
166
166
  raise AdapterCannotListenError unless pg_conn.respond_to? :wait_for_notify
@@ -1,4 +1,4 @@
1
1
  module GoodJob
2
2
  # GoodJob gem version.
3
- VERSION = '1.9.0'.freeze
3
+ VERSION = '1.9.1'.freeze
4
4
  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: 1.9.0
4
+ version: 1.9.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: 2021-04-16 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob