Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify parent class for active record #238

Merged
merged 2 commits into from
Apr 19, 2021

Conversation

morgoth
Copy link
Collaborator

@morgoth morgoth commented Apr 16, 2021

Refs #236

POC

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very reasonable 👍

@@ -143,7 +143,7 @@ def with_advisory_lock
def supports_cte_materialization_specifiers?
return @_supports_cte_materialization_specifiers if defined?(@_supports_cte_materialization_specifiers)

@_supports_cte_materialization_specifiers = ActiveRecord::Base.connection.postgresql_version >= 120000
@_supports_cte_materialization_specifiers = Job.connection.postgresql_version >= 120000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GoodJob::Lockable class is intended to be a generic ActiveRecord mixin, so this hopefully can be:

Suggested change
@_supports_cte_materialization_specifiers = Job.connection.postgresql_version >= 120000
@_supports_cte_materialization_specifiers = self.class.connection.postgresql_version >= 120000

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this doesn't work somehow

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. This is within class_methods so it just needs to be: connection.postgresql_version >= 120000

@@ -158,7 +158,7 @@ def advisory_lock
WHERE pg_try_advisory_lock(('x'||substr(md5($1 || $2::text), 1, 16))::bit(64)::bigint)
SQL
binds = [[nil, self.class.table_name], [nil, send(self.class.primary_key)]]
ActiveRecord::Base.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?
Job.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
Job.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).any?

@@ -2,7 +2,7 @@ module GoodJob
#
# Represents a request to perform an +ActiveJob+ job.
#
class Job < ActiveRecord::Base
class Job < Object.const_get(GoodJob.active_record_parent_class)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lib/good_job.rb Outdated
@@ -17,6 +17,9 @@
#
# +GoodJob+ is the top-level namespace and exposes configuration attributes.
module GoodJob
# TODO: explain me
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: explain me
# @!attribute [rw] active_record_parent_class
# @!scope class
# The ActiveRecord parent class inherited by +GoodJob::Job+ (default: +ActiveRecord::Base+).
# Use this when using multiple databases or other custom ActiveRecord configuration.
# @return [ActiveRecord::Base]
# @example Change the base class:
# GoodJob.active_record_parent_class = "CustomApplicationRecord"

@morgoth morgoth marked this pull request as ready for review April 17, 2021 09:50
@morgoth
Copy link
Collaborator Author

morgoth commented Apr 19, 2021

@bensheldon Anything more I should add to make it merged? I was thinking about some spec, but it might be tricky to test inheritance as the job file is already loaded on spec run.

@bensheldon
Copy link
Owner

@morgoth I agree about the difficulty of testing. It seems like it will either work, or fail across the board. Let's move it forward and see what we learn.

@bensheldon bensheldon merged commit 9f87ffb into bensheldon:main Apr 19, 2021
@bensheldon
Copy link
Owner

I forgot that this should also be documented in the Readme. Done in 9eac0be

@bensheldon
Copy link
Owner

This has been released in v1.9.1

@bensheldon bensheldon added the enhancement New feature or request label May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants