Skip to content

Commit

Permalink
Remove old compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Aug 9, 2024
1 parent ea9e102 commit cea8018
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 44 deletions.
9 changes: 1 addition & 8 deletions app/models/concerns/good_job/advisory_lockable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ module AdvisoryLockable
cte_table = Arel::Table.new(:rows)
cte_query = original_query.select(primary_key, column).except(:limit)
cte_query = cte_query.limit(select_limit) if select_limit
cte_type = supports_cte_materialization_specifiers? ? :MATERIALIZED : :""
composed_cte = Arel::Nodes::As.new(cte_table, Arel::Nodes::UnaryOperation.new(cte_type, cte_query.arel))
composed_cte = Arel::Nodes::As.new(cte_table, Arel::Nodes::UnaryOperation.new(:MATERIALIZED, cte_query.arel))

lock_condition = "#{function}(('x' || substr(md5(#{connection.quote(table_name)} || '-' || #{connection.quote_table_name(cte_table.name)}.#{connection.quote_column_name(column)}::text), 1, 16))::bit(64)::bigint)"
query = cte_table.project(cte_table[:id])
Expand Down Expand Up @@ -281,12 +280,6 @@ def _advisory_lockable_column
advisory_lockable_column || primary_key
end

def supports_cte_materialization_specifiers?
return @_supports_cte_materialization_specifiers if defined?(@_supports_cte_materialization_specifiers)

@_supports_cte_materialization_specifiers = connection.postgresql_version >= 120000
end

# Postgres advisory unlocking function for the class
# @param function [String, Symbol] name of advisory lock or unlock function
# @return [Boolean]
Expand Down
13 changes: 2 additions & 11 deletions app/models/concerns/good_job/filterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,9 @@ module Filterable

# TODO: turn this into proper bind parameters in Arel
tsvector = "(to_tsvector('english', id::text) || to_tsvector('english', COALESCE(active_job_id::text, '')) || to_tsvector('english', serialized_params) || to_tsvector('english', COALESCE(error, '')) || to_tsvector('english', COALESCE(array_to_string(labels, ' '), '')))"
to_tsquery_function = database_supports_websearch_to_tsquery? ? 'websearch_to_tsquery' : 'plainto_tsquery'
where("#{tsvector} @@ #{to_tsquery_function}(?)", query)
.order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, #{to_tsquery_function}(?))"), query]) => 'DESC')
where("#{tsvector} @@ websearch_to_tsquery(?)", query)
.order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, websearch_to_tsquery(?))"), query]) => 'DESC')
end)
end

class_methods do
def database_supports_websearch_to_tsquery?
return @_database_supports_websearch_to_tsquery if defined?(@_database_supports_websearch_to_tsquery)

@_database_supports_websearch_to_tsquery = connection.postgresql_version >= 110000
end
end
end
end
6 changes: 1 addition & 5 deletions app/models/good_job/batch_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def self.load(value)
end
end

if Rails.gem_version < Gem::Version.new('6.1.0.alpha')
# serialize does not yet take a default value, must set via Attributes API
attribute :serialized_properties, :json, default: -> { {} }
serialize :serialized_properties, PropertySerializer
elsif Rails.gem_version < Gem::Version.new('7.1.0.alpha')
if Rails.gem_version < Gem::Version.new('7.1.0.alpha')
serialize :serialized_properties, PropertySerializer, default: -> { {} }
else
serialize :serialized_properties, coder: PropertySerializer, default: -> { {} }
Expand Down
6 changes: 1 addition & 5 deletions demo/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
config.active_job.queue_adapter = :test

# Raises error for missing translations.
if Gem::Version.new(Rails.version) < Gem::Version.new('6.1')
config.action_view.raise_on_missing_translations = true
else
config.i18n.raise_on_missing_translations = true
end
config.i18n.raise_on_missing_translations = true

config.colorize_logging = false if ENV["CI"]
if ActiveModel::Type::Boolean.new.cast(ENV['RAILS_LOG_TO_STDOUT'])
Expand Down
6 changes: 3 additions & 3 deletions spec/app/models/concerns/good_job/advisory_lockable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
SELECT "good_jobs".*
FROM "good_jobs"
WHERE "good_jobs"."id" IN (
WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} (
WITH "rows" AS MATERIALIZED (
SELECT "good_jobs"."id", "good_jobs"."id"
FROM "good_jobs"
WHERE "good_jobs"."priority" = 99
Expand All @@ -73,7 +73,7 @@
SELECT "good_jobs".*
FROM "good_jobs"
WHERE "good_jobs"."id" IN (
WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} (
WITH "rows" AS MATERIALIZED (
SELECT "good_jobs"."id", "good_jobs"."queue_name"
FROM "good_jobs"
ORDER BY "good_jobs"."priority" DESC
Expand All @@ -95,7 +95,7 @@
SELECT "good_jobs".*
FROM "good_jobs"
WHERE "good_jobs"."id" IN (
WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} (
WITH "rows" AS MATERIALIZED (
SELECT "good_jobs"."id", "good_jobs"."active_job_id"
FROM "good_jobs"
LIMIT 1000
Expand Down
10 changes: 4 additions & 6 deletions spec/lib/good_job/active_job_extensions/concurrency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def perform(name:)
end

describe '.good_job_control_concurrency_with' do
describe 'total_limit:', :skip_rails_5 do
describe 'total_limit:' do
before do
TestJob.good_job_control_concurrency_with(
total_limit: -> { 1 },
Expand All @@ -75,7 +75,7 @@ def perform(name:)
end
end

describe 'enqueue_limit:', :skip_rails_5 do
describe 'enqueue_limit:' do
before do
TestJob.good_job_control_concurrency_with(
enqueue_limit: -> { 2 },
Expand All @@ -99,10 +99,8 @@ def perform(name:)
expect(GoodJob::Job.where(concurrency_key: "Bob").count).to eq 1

expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Aborted enqueue of TestJob \(Job ID: .*\) because the concurrency key 'Alice' has reached its enqueue limit of 2 jobs/)).exactly(:once)
if ActiveJob.gem_version >= Gem::Version.new("6.1.0")
expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Alice"}/)).exactly(:twice)
expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Bob"}/)).exactly(:once)
end
expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Alice"}/)).exactly(:twice)
expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Bob"}/)).exactly(:once)
end

it 'excludes jobs that are already executing/locked' do
Expand Down
6 changes: 0 additions & 6 deletions spec/support/rails_versions.rb

This file was deleted.

0 comments on commit cea8018

Please sign in to comment.